2 ** Copyright (c) 2013-2019 Mahmoud Fayed <msfclipper@yahoo.com>
7 RING_API Item * ring_item_new_gc ( void *pState,int ItemType )
10 pItem = (Item *) ring_state_malloc(pState,sizeof(Item));
11 if ( pItem == NULL ) {
16 pItem->nType = ITEMTYPE_NOTHING ;
17 /* Delete pointer information */
18 pItem->data.pPointer = NULL ;
19 pItem->nObjectType = 0 ;
20 /* Delete number information */
21 pItem->data.dNumber = 0 ;
22 pItem->data.iNumber = 0 ;
23 pItem->NumberFlag = ITEM_NUMBERFLAG_NOTHING ;
25 ring_vm_gc_cleardata(pItem);
26 ring_item_settype_gc(pState,pItem,ItemType);
30 RING_API Item * ring_item_delete_gc ( void *pState,Item *pItem )
32 assert(pItem != NULL);
33 ring_vm_gc_deleteitem_gc(pState,pItem);
37 RING_API void ring_item_print ( Item *pItem )
40 assert(pItem != NULL);
41 ItemType = pItem->nType ;
43 case ITEMTYPE_NOTHING :
46 case ITEMTYPE_STRING :
48 ring_string_print(pItem->data.pString);
50 case ITEMTYPE_NUMBER :
52 if ( pItem->NumberFlag == ITEM_NUMBERFLAG_INT ) {
53 printf( "%d\n ",pItem->data.iNumber ) ;
55 printf( "%f \n",pItem->data.dNumber ) ;
58 case ITEMTYPE_POINTER :
60 printf( "%p",pItem->data.pPointer ) ;
64 ring_list_print(pItem->data.pList);
69 RING_API void ring_item_content_delete_gc ( void *pState,Item *pItem )
71 assert(pItem != NULL);
72 switch ( pItem->nType ) {
73 case ITEMTYPE_STRING :
75 pItem->data.pString = ring_string_delete_gc(pState,pItem->data.pString);
79 pItem->data.pList = ring_list_delete_gc(pState,pItem->data.pList);
83 pItem->nType = ITEMTYPE_NOTHING ;
84 /* Delete pointer information */
85 pItem->data.pPointer = NULL ;
86 pItem->nObjectType = 0 ;
87 /* Delete number information */
88 pItem->data.dNumber = 0 ;
89 pItem->data.iNumber = 0 ;
90 pItem->NumberFlag = ITEM_NUMBERFLAG_NOTHING ;
93 RING_API void ring_item_settype_gc ( void *pState,Item *pItem,int ItemType )
95 assert(pItem != NULL);
96 /* When we set the type we remove the current content at first */
97 ring_item_content_delete_gc(pState,pItem);
99 case ITEMTYPE_NOTHING :
100 pItem->nType = ITEMTYPE_NOTHING ;
102 case ITEMTYPE_STRING :
103 pItem->nType = ITEMTYPE_STRING ;
104 pItem->data.pString = ring_string_new_gc(pState,"");
106 case ITEMTYPE_NUMBER :
107 pItem->nType = ITEMTYPE_NUMBER ;
108 pItem->data.dNumber = 0 ;
109 pItem->data.iNumber = 0 ;
111 case ITEMTYPE_POINTER :
112 pItem->nType = ITEMTYPE_POINTER ;
113 pItem->data.pPointer = NULL ;
114 pItem->nObjectType = 0 ;
117 pItem->nType = ITEMTYPE_LIST ;
118 pItem->data.pList = ring_list_new_gc(pState,0);
120 case ITEMTYPE_FUNCPOINTER :
121 pItem->nType = ITEMTYPE_FUNCPOINTER ;
122 pItem->data.pFunc = NULL ;
127 ** Functions to deal with array of items
131 RING_API void ring_itemarray_setint_gc ( void *pState,Item pList[], int index ,int number )
133 ring_item_settype_gc(pState,&pList[index],ITEMTYPE_NUMBER);
134 pList[index].data.iNumber = number ;
135 pList[index].NumberFlag = ITEM_NUMBERFLAG_INT ;
139 RING_API void ring_itemarray_setpointer_gc ( void *pState,Item pList[], int index ,void *pValue )
141 ring_item_settype_gc(pState,&pList[index],ITEMTYPE_POINTER);
142 pList[index].data.pPointer = pValue ;
143 pList[index].nObjectType = 0 ;
147 RING_API void ring_itemarray_setdouble_gc ( void *pState,Item pList[], int index ,double number )
149 ring_item_settype_gc(pState,&pList[index],ITEMTYPE_NUMBER);
150 pList[index].data.dNumber = number ;
151 pList[index].NumberFlag = ITEM_NUMBERFLAG_DOUBLE ;
153 #define ring_list_getint(pList,index) ( ring_list_getitem(pList,index)->data.iNumber )
154 #define ring_list_getpointer(pList,index) ( ring_list_getitem(pList,index)->data.pPointer )
155 #define ring_list_getfuncpointer(pList,index) ( ring_list_getitem(pList,index)->data.pFunc )
156 #define ring_list_callfuncpointer(pList,index,x) ( ring_list_getitem(pList,index)->data.pFunc(x) )
157 #define ring_list_getdouble(pList,index) ring_list_getitem(pList,index)->data.dNumber
158 #define ring_list_getstring(pList,index) ( ring_string_get(ring_item_getstring(ring_list_getitem(pList,index))) )
159 #define ring_list_getstringobject(pList,index) ( ring_item_getstring(ring_list_getitem(pList,index)) )
160 #define ring_list_getstringsize(pList,index) ( ring_string_size(ring_item_getstring(ring_list_getitem(pList,index))) )
163 RING_API void ring_itemarray_setstring_gc ( void *pState,Item pList[], int index ,const char *str )
165 ring_item_settype_gc(pState,&pList[index],ITEMTYPE_STRING);
166 ring_string_set_gc(pState,pList[index].data.pString ,str);
169 RING_API void ring_itemarray_setstring2_gc ( void *pState,Item pList[], int index ,const char *str,int nStrSize )
171 ring_item_settype_gc(pState,&pList[index],ITEMTYPE_STRING);
172 ring_string_set2_gc(pState,pList[index].data.pString ,str,nStrSize);
174 /* Functions to deal with one item */
176 RING_API void ring_item_setstring_gc ( void *pState,Item *pItem,const char *cStr )
178 ring_item_settype_gc(pState,pItem,ITEMTYPE_STRING);
179 ring_string_set_gc(pState,ring_item_getstring(pItem),cStr);
182 RING_API void ring_item_setstring2_gc ( void *pState,Item *pItem,const char *cStr,int nStrSize )
184 ring_item_settype_gc(pState,pItem,ITEMTYPE_STRING);
185 ring_string_set2_gc(pState,ring_item_getstring(pItem),cStr,nStrSize);
188 RING_API void ring_item_setdouble_gc ( void *pState,Item *pItem,double x )
190 ring_item_settype_gc(pState,pItem,ITEMTYPE_NUMBER);
191 pItem->data.dNumber = x ;
192 pItem->NumberFlag = ITEM_NUMBERFLAG_DOUBLE ;
195 RING_API void ring_item_setpointer_gc ( void *pState,Item *pItem,void *pValue )
197 ring_item_settype_gc(pState,pItem,ITEMTYPE_POINTER);
198 pItem->data.pPointer = pValue ;
199 pItem->nObjectType = 0 ;
202 RING_API void ring_item_setint_gc ( void *pState,Item *pItem,int x )
204 ring_item_settype_gc(pState,pItem,ITEMTYPE_NUMBER);
205 pItem->data.iNumber = x ;
206 pItem->NumberFlag = ITEM_NUMBERFLAG_INT ;
208 /* Functions without state pointer */
210 RING_API Item * ring_item_new ( int ItemType )
212 return ring_item_new_gc(NULL,ItemType) ;
215 RING_API Item * ring_item_delete ( Item *pItem )
217 return ring_item_delete_gc(NULL,pItem) ;
220 RING_API void ring_item_settype ( Item *pItem,int ItemType )
222 ring_item_settype_gc(NULL,pItem,ItemType);
225 RING_API void ring_item_content_delete ( Item *pItem )
227 ring_item_content_delete_gc(NULL,pItem);
230 ** Functions to deal with array of items
234 RING_API void ring_itemarray_setint ( Item pList[], int index ,int number )
236 ring_itemarray_setint_gc(NULL,pList,index,number);
240 RING_API void ring_itemarray_setpointer ( Item pList[], int index ,void *pValue )
242 ring_itemarray_setpointer_gc(NULL,pList,index,pValue);
246 RING_API void ring_itemarray_setdouble ( Item pList[], int index ,double number )
248 ring_itemarray_setdouble_gc(NULL,pList,index,number);
252 RING_API void ring_itemarray_setstring ( Item pList[], int index ,const char *str )
254 ring_itemarray_setstring_gc(NULL,pList,index,str);
257 RING_API void ring_itemarray_setstring2 ( Item pList[], int index ,const char *str,int nStrSize )
259 ring_itemarray_setstring2_gc(NULL,pList,index,str,nStrSize);
261 /* Functions to deal with one item */
263 RING_API void ring_item_setstring ( Item *pItem,const char *cStr )
265 ring_item_setstring_gc(NULL,pItem,cStr);
268 RING_API void ring_item_setdouble ( Item *pItem,double x )
270 ring_item_setdouble_gc(NULL,pItem,x);
273 RING_API void ring_item_setpointer ( Item *pItem,void *pValue )
275 ring_item_setpointer_gc(NULL,pItem,pValue);
278 RING_API void ring_item_setint ( Item *pItem,int x )
280 ring_item_setint_gc(NULL,pItem,x);
283 RING_API void ring_item_setstring2 ( Item *pItem,const char *cStr,int nStrSize )
285 ring_item_setstring2_gc(NULL,pItem,cStr,nStrSize);