7 __attribute__((unused)) static void UnusedFunction()
10 a.OnGetDataFromString(null);
11 a.OnGetString(null, 0, 0);
14 extern int __ecereVMethodID_class_OnGetDataFromString;
15 extern int __ecereVMethodID_class_OnGetString;
16 extern int __ecereVMethodID_class_OnFree;
19 public enum JSONResult { syntaxError, success, typeMismatch, noItem };
21 public enum SetBool : uint
25 /*public property bool // NOT WORKING!
27 set { return value ? true : false; }
28 get { return (this == true); }
33 public class JSONParser
41 while(!f.Eof() && (!ch || ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'))
47 JSONResult GetValue(Class type, DataValue value)
49 JSONResult result = syntaxError;
55 result = GetString(&string);
59 if(type && (!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *")))
63 else if(type && (type.type == enumClass || type.type == unitClass))
65 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, &value.i, string))
68 result = typeMismatch;
71 else if(type && (prop = eClass_FindProperty(type, "String", type.module)))
73 // TOFIX: Add more conversion property support... Expecting void * compatible here
74 value.p = ((void *(*)())(void *)prop.Set)(string);
78 else if(type && (type.type == structClass))
80 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, value.p, string))
83 result = typeMismatch;
89 result = typeMismatch;
96 if(type && eClass_IsDerived(type, class(Map)))
98 result = GetMap(type, (Map *)&array);
101 result = GetArray(type, &array);
103 if(result == success && type && eClass_IsDerived(type, class(Container)))
112 if(result != success)
113 result = typeMismatch;
116 else if(ch == '-' || isdigit(ch))
118 result = GetNumber(type, value);
122 void * object = value.p;
123 result = GetObject(type, &object);
126 if(type && type.type == structClass);
127 else if(type && (type.type == normalClass || type.type == noHeadClass || type.type == bitClass))
133 result = typeMismatch;
135 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, object);
143 while(c < sizeof(buffer)-1 && isalpha(ch))
146 if(!f.Getc(&ch)) break;
153 if(!strcmp(type.name, "bool"))
155 if(!strcmpi(buffer, "false")) value.i = 0;
156 else if(!strcmpi(buffer, "true")) value.i = 1;
158 result = typeMismatch;
160 else if(!strcmp(type.name, "SetBool"))
162 if(!strcmpi(buffer, "false")) value.i = SetBool::false;
163 else if(!strcmpi(buffer, "true")) value.i = SetBool::true;
165 result = typeMismatch;
167 else if(!strcmpi(buffer, "null"))
172 result = typeMismatch;
175 result = typeMismatch;
177 else if(ch == '}' || ch == ']')
182 JSONResult GetArray(Class type, Container * array)
184 JSONResult result = syntaxError;
189 *array = eInstance_New(type);
194 Class arrayType = null;
195 JSONResult itemResult;
197 if(eClass_IsDerived(type, class(Container)))
199 arrayType = type.templateArgs[0].dataTypeClass;
202 if(arrayType && arrayType.type == structClass)
203 value.p = new0 byte[arrayType.structSize];
204 itemResult = GetValue(arrayType, value);
205 if(itemResult == success)
207 // TODO: Verify the matching between template type and uint64
209 if(arrayType.type == structClass)
211 t = (uint64)(uintptr)value.p;
213 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
215 t = value.ui64; //*(uint64 *)&value.d;
217 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
219 t = value.ui; //f*(uint *)&value.f;
221 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
222 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
226 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
227 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
231 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
232 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
233 !strcmp(arrayType.dataTypeString, "int16"))
237 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
238 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
244 t = (uint64)(uintptr)value.p;
246 ((void *(*)(void *, uint64))(void *)array->Add)(*array, t);
248 if(arrayType && arrayType.type == structClass)
253 if(itemResult == typeMismatch)
256 PrintLn("Warning: Incompatible value for array value, expected ", (String)arrayType.name);
258 else if(itemResult == noItem)
264 if(result != syntaxError)
266 if(ch != ']' && ch != ',')
276 result = syntaxError;
284 JSONResult GetMap(Class type, Map * map)
286 JSONResult result = syntaxError;
291 Class mapNodeType = type.templateArgs[0].dataTypeClass;
292 Class keyType = mapNodeType.templateArgs[0].dataTypeClass;
293 Property keyProp = null;
294 if(keyType && !strcmp(keyType.dataTypeString, "char *"))
295 keyProp = eClass_FindProperty(mapNodeType, "key", mapNodeType.module);
297 *map = eInstance_New(type);
304 JSONResult itemResult;
306 itemResult = GetValue(mapNodeType, value);
307 if(itemResult == success)
309 String s = keyProp ? ((void * (*)(void *))(void *)keyProp.Get)(value.p) : null;
310 ((void *(*)(void *, uint64))(void *)map->Add)(*map, (uint64)(uintptr)value.p);
311 // Must free String keys here
316 if(itemResult == typeMismatch)
319 PrintLn("Warning: Incompatible value for array value, expected ", (String)mapNodeType.name);
321 else if(itemResult == noItem)
327 if(result != syntaxError)
329 if(ch != ']' && ch != ',')
339 result = syntaxError;
347 JSONResult GetString(String * string)
349 JSONResult result = syntaxError;
350 Array<char> buffer { minAllocSize = 256 };
351 bool escaped = false;
359 if(ch == '\\' && !escaped)
365 if(ch == 'b') ch = '\b';
366 else if(ch == 'f') ch = '\f';
367 else if(ch == 'n') ch = '\n';
368 else if(ch == 'r') ch = '\r';
369 else if(ch == 't') ch = '\t';
386 if(buffer.minAllocSize < buffer.count)
387 buffer.minAllocSize *= 2;
391 *string = CopyString(buffer.array);
395 if(ch != ',' && ch != '}')
400 public JSONResult GetObject(Class objectType, void ** object)
402 JSONResult result = syntaxError;
403 if(!objectType || objectType.type != structClass)
408 Class mapKeyClass = null, mapDataClass = null;
410 if(objectType && objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
412 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
413 mapDataClass = objectType.templateArgs[2].dataTypeClass;
417 if(objectType && (objectType.type == noHeadClass || objectType.type == normalClass))
419 *object = eInstance_New(objectType);
421 else if(objectType && objectType.type != structClass)
423 *object = eSystem_New(objectType.typeSize);
430 if(GetString(&string))
432 DataMember member = null;
433 Property prop = null;
440 string[0] = (char)tolower(string[0]);
441 if(mapKeyClass && !strcmp(string, "key"))
443 prop = eClass_FindProperty(objectType, "key", objectType.module);
447 else if(mapDataClass && !strcmp(string, "value"))
449 prop = eClass_FindProperty(objectType, "value", objectType.module);
454 member = eClass_FindDataMember(objectType, string, objectType.module, null, null);
457 type = eSystem_FindClass(__thisModule, member.dataTypeString);
459 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
461 offset = member._class.offset + member.offset;
465 prop = eClass_FindProperty(objectType, string, objectType.module);
468 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
470 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
473 PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
477 // Find Member in Object Class
481 if(type && type.type == structClass)
485 value.p = (byte *)*object + offset;
486 memset(value.p, 0, type.structSize);
490 value.p = new0 byte[type.structSize];
497 JSONResult itemResult = GetValue(type, value);
498 if(itemResult != syntaxError)
504 PrintLn("warning: Unresolved data type ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
506 else if(itemResult == success)
511 // TOFIX: How to swiftly handle classes with base data type?
512 if(type.type == structClass)
514 else if(type.type == normalClass || type.type == noHeadClass)
516 void ** ptr = (void**)((byte *)*object + offset);
517 if(eClass_IsDerived(type, class(Container)) && *ptr)
519 Container container = (Container)*ptr;
525 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
527 *(double *)((byte *)*object + offset) = value.d;
529 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
531 *(float *)((byte *)*object + offset) = value.f;
533 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
534 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
536 *(uint64 *)((byte *)*object + offset) = value.ui64;
538 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
539 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
541 *(int *)((byte *)*object + offset) = value.i;
543 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
544 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
545 !strcmp(type.dataTypeString, "int16"))
547 *(short *)((byte *)*object + offset) = value.s;
549 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
550 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
552 *(char *)((byte *)*object + offset) = value.c;
556 *(void **)((byte *)*object + offset) = value.p;
559 else if(prop && prop.Set)
561 if(!strcmp(type.dataTypeString, "char *"))
563 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
567 // TOFIX: How to swiftly handle classes with base data type?
568 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
570 ((void (*)(void *, double))(void *)prop.Set)(*object, value.d);
572 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
574 ((void (*)(void *, float))(void *)prop.Set)(*object, value.f);
576 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
577 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
579 ((void (*)(void *, uint64))(void *)prop.Set)(*object, value.ui64);
581 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
582 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
584 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
586 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
587 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
588 !strcmp(type.dataTypeString, "int16"))
590 ((void (*)(void *, short))(void *)prop.Set)(*object, value.s);
592 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
593 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
595 ((void (*)(void *, char))(void *)prop.Set)(*object, value.c);
599 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
605 PrintLn("Warning: Incompatible value for ", member ? (String)member.name : (String)prop.name,
606 ", expected ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
612 result = syntaxError;
614 if(prop && type.type == structClass)
620 else if(ch && ch != '}' && ch != ',')
621 result = syntaxError;
632 result = syntaxError;
640 JSONResult GetNumber(Class type, DataValue value)
642 JSONResult result = syntaxError;
645 while(c < sizeof(buffer)-1 && (ch == '-' || ch == '.' || tolower(ch) == 'e' || ch == '+' || isdigit(ch)))
648 if(!f.Getc(&ch)) break;
651 //if(strchr(buffer, '.'))
652 if(!type) return success;
654 // TOFIX: How to swiftly handle classes with base data type?
655 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
657 value.d = strtod(buffer, null);
660 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
662 value.f = (float)strtod(buffer, null);
665 // TOFIX: int64 looks for class long long?
666 //else if(type == class(int64) || !strcmp(type.dataTypeString, "int64"))
667 else if(!strcmp(type.dataTypeString, "int64"))
669 value.i64 = strtol(buffer, null, 10); // TOFIX: 64 bit support
672 else if(type == class(uint64) || !strcmp(type.dataTypeString, "uint64"))
674 value.ui64 = strtoul(buffer, null, 10); // TOFIX: 64 bit support
677 else if(type == class(uint) || !strcmp(type.dataTypeString, "unsigned int"))
679 value.ui = (uint)strtoul(buffer, null, 10); // TOFIX: 64 bit support
684 value.i = (int)strtol(buffer, null, 10);
688 if(result == success && type.type == unitClass)
690 // Convert to reference unit
692 for(prop = type.conversions.first; prop; prop = prop.next)
694 bool refProp = false;
696 if(!strcmp(prop.name, type.base.fullName))
698 else if( (c = eSystem_FindClass(type.module, prop.name) ) )
701 for(p = c.conversions.first; p; p = p.next)
703 if(!strcmp(p.name, type.base.fullName) && !p.Set && !p.Get)
712 if(prop.Set && prop.Get)
714 const String dts = type.base.dataTypeString;
715 if(!strcmp(dts, "double"))
716 value.d = ((double(*)(double))(void *)prop.Get)(value.d);
717 else if(!strcmp(dts, "float"))
718 value.f = ((float(*)(float))(void *)prop.Get)(value.f);
719 else if(!strcmp(dts, "int"))
720 value.i = ((int(*)(int))(void *)prop.Get)(value.i);
721 else if(!strcmp(dts, "int64"))
722 value.i64 = ((int64(*)(int64))(void *)prop.Get)(value.i64);
723 else if(!strcmp(dts, "unsigned int"))
724 value.ui = ((uint(*)(uint))(void *)prop.Get)(value.ui);
725 else if(!strcmp(dts, "uint64"))
726 value.ui64 = ((uint64(*)(uint64))(void *)prop.Get)(value.ui64);
737 bool WriteMap(File f, Class type, Map map, int indent)
743 MapIterator it { map = map };
744 Class mapNodeClass = map._class.templateArgs[0].dataTypeClass;
750 MapNode n = (MapNode)it.pointer;
755 for(i = 0; i<indent; i++) f.Puts(" ");
756 _WriteJSONObject(f, mapNodeClass, n, indent);
760 for(i = 0; i<indent; i++) f.Puts(" ");
768 bool WriteArray(File f, Class type, Container array, int indent)
774 Iterator it { array };
775 Class arrayType = type.templateArgs[0].dataTypeClass;
782 uint64 t = ((uint64(*)(void *, void *))(void *)array.GetData)(array, it.pointer);
789 // TODO: Verify the matching between template type and uint64
790 if(arrayType.type == structClass)
792 value.p = (void *)(uintptr)t;
794 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
797 //value.d = *(double *)&t;
799 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
802 //value.f = *(float *)&t;
804 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
805 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
809 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
810 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
814 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
815 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
816 !strcmp(arrayType.dataTypeString, "int16"))
820 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
821 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
827 value.p = (void *)(uintptr)t;
829 for(i = 0; i<indent; i++) f.Puts(" ");
830 WriteValue(f, arrayType, value, indent);
834 for(i = 0; i<indent; i++) f.Puts(" ");
842 bool WriteNumber(File f, Class type, DataValue value, int indent)
845 bool needClass = false;
848 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
849 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.d, buffer, 0, &needClass);
850 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
851 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.f, buffer, null, &needClass);
852 else if(!strcmp(type.dataTypeString, "int64"))
853 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i64, buffer, null, &needClass);
854 else if(!strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64") || type.typeSize == sizeof(int64))
855 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui64, buffer, null, &needClass);
856 else if(!strcmp(type.dataTypeString, "int"))
857 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i, buffer, null, &needClass);
858 else if(!strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint") || type.typeSize == sizeof(int))
859 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui, buffer, null, &needClass);
860 else if(!strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "int16"))
861 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.s, buffer, null, &needClass);
862 else if(!strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") || type.typeSize == sizeof(short int))
863 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.us, buffer, null, &needClass);
864 else if(!strcmp(type.dataTypeString, "char"))
865 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.c, buffer, null, &needClass);
866 else if(!strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte") || type.typeSize == sizeof(byte))
867 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.uc, buffer, null, &needClass);
869 quote = (type.type == unitClass && ((buffer[0] != '.' && !isdigit(buffer[0])) || strchr(buffer, ' ')));
870 if(quote) f.Puts("\"");
872 if(quote) f.Puts("\"");
876 bool WriteValue(File f, Class type, DataValue value, int indent)
878 if(!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *"))
885 //if(strchr(value.p, '\"') || strchr(value.p, '\\'))
890 char * string = value.p;
909 else if(b == sizeof(buffer)-2 || !ch)
912 if(ch) buffer[b] = 0;
926 else if(!strcmp(type.name, "bool"))
933 else if(!strcmp(type.name, "SetBool"))
935 if(value.i == SetBool::true)
937 else if(value.i == SetBool::false)
942 else if(type.type == enumClass)
945 WriteNumber(f, type, value, indent);
948 else if(eClass_IsDerived(type, class(Map)))
950 WriteMap(f, type, value.p, indent);
952 else if(eClass_IsDerived(type, class(Container)))
954 WriteArray(f, type, value.p, indent);
956 else if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
958 _WriteJSONObject(f, type, value.p, indent);
960 else if(type.type == bitClass)
963 dataType = eSystem_FindClass(__thisModule, type.dataTypeString);
964 WriteNumber(f, dataType, value, indent);
966 else if(type.type == systemClass || type.type == unitClass)
968 WriteNumber(f, type, value, indent);
973 public bool WriteJSONObject(File f, Class objectType, void * object, int indent)
978 result = _WriteJSONObject(f, objectType, object, indent);
984 static bool _WriteJSONObject(File f, Class objectType, void * object, int indent)
988 const char * string = null;
990 if(objectType._vTbl[__ecereVMethodID_class_OnGetString] != objectType.base._vTbl[__ecereVMethodID_class_OnGetString])
994 string = ((const char *(*)())(void *)objectType._vTbl[__ecereVMethodID_class_OnGetString])(objectType, object, buffer, null, null);
998 // TOCHECK: ProjectNode.ec why do we add quotes in OnGetString there?
999 if(string[0] == '\"')
1012 bool isFirst = true;
1013 Class mapKeyClass = null, mapDataClass = null;
1015 List<Class> bases { };
1017 if(objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
1019 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
1020 mapDataClass = objectType.templateArgs[2].dataTypeClass;
1026 for(baseClass = objectType; baseClass; baseClass = baseClass.base)
1028 if(baseClass.isInstanceClass || !baseClass.base)
1030 bases.Insert(null, baseClass);
1033 for(baseClass : bases)
1035 for(prop = baseClass.membersAndProperties.first; prop; prop = prop.next)
1037 if(prop.memberAccess != publicAccess || (prop.isProperty && (!prop.Set || !prop.Get))) continue;
1040 if(!prop.conversion && (!prop.IsSet || prop.IsSet(object)))
1042 DataValue value { };
1045 if(mapKeyClass && !strcmp(prop.name, "key"))
1047 else if(mapDataClass && !strcmp(prop.name, "value"))
1048 type = mapDataClass;
1050 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
1052 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
1054 PrintLn("warning: Unresolved data type ", (String)prop.dataTypeString);
1057 // TOFIX: How to swiftly handle classes with base data type?
1058 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1060 value.d = ((double (*)(void *))(void *)prop.Get)(object);
1062 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1064 value.f = ((float (*)(void *))(void *)prop.Get)(object);
1066 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1067 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1069 value.ui64 = ((uint64 (*)(void *))(void *)prop.Get)(object);
1071 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1072 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1074 value.i = ((int (*)(void *))(void *)prop.Get)(object);
1076 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1077 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1078 !strcmp(type.dataTypeString, "int16"))
1080 value.s = ((short (*)(void *))(void *)prop.Get)(object);
1082 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1083 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1085 value.c = ((char (*)(void *))(void *)prop.Get)(object);
1087 else if(type.type == structClass)
1089 value.p = new0 byte[type.structSize];
1090 ((void (*)(void *, void *))(void *)prop.Get)(object, value.p);
1094 value.p = ((void *(*)(void *))(void *)prop.Get)(object);
1097 if(!isFirst) f.Puts(",\n");
1098 for(c = 0; c<indent; c++) f.Puts(" ");
1101 f.Putc((char)toupper(prop.name[0]));
1102 f.Puts(prop.name+1);
1104 WriteValue(f, type, value, indent);
1106 if(type.type == structClass)
1113 DataMember member = (DataMember)prop;
1114 DataValue value { };
1116 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
1118 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
1120 offset = member._class.offset + member.offset;
1124 if(type.type == normalClass || type.type == noHeadClass || type.type == structClass || !strcmp(type.name, "String"))
1126 if(type.type == structClass)
1127 value.p = (void *)((byte *)object + offset);
1129 value.p = *(void **)((byte *)object + offset);
1133 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1135 value.d = *(double *)((byte *)object + offset);
1137 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1139 value.f = *(float *)((byte *)object + offset);
1141 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1142 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1144 value.ui64 = *(uint64 *)((byte *)object + offset);
1146 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1147 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1149 value.i = *(int *)((byte *)object + offset);
1150 if(!strcmp(type.name, "bool") || type.type == enumClass)
1154 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1155 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1156 !strcmp(type.dataTypeString, "int16"))
1158 value.s = *(short *)((byte *)object + offset);
1160 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1161 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1163 value.c = *(char *)((byte *)object + offset);
1167 value.i = *(int *)((byte *)object + offset);
1170 if(!isFirst) f.Puts(",\n");
1171 for(c = 0; c<indent; c++) f.Puts(" ");
1174 f.Putc((char)toupper(member.name[0]));
1175 f.Puts(member.name+1);
1177 WriteValue(f, type, value, indent);
1188 for(c = 0; c<indent; c++) f.Puts(" "); f.Puts("}");