8 __attribute__((unused)) static void UnusedFunction()
11 a.OnGetDataFromString(null);
12 a.OnGetString(null, 0, 0);
15 extern int __ecereVMethodID_class_OnGetDataFromString;
16 extern int __ecereVMethodID_class_OnGetString;
17 extern int __ecereVMethodID_class_OnFree;
20 public enum JSONResult { syntaxError, success, typeMismatch, noItem };
22 public enum SetBool : uint
26 /*public property bool // NOT WORKING!
28 set { return value ? true : false; }
29 get { return (this == true); }
34 public class JSONParser
42 while(!f.Eof() && (!ch || ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '/'))
48 JSONResult GetValue(Class type, DataValue value)
50 JSONResult result = syntaxError;
56 result = GetString(&string);
60 if(type && (!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *")))
64 else if(type && (type.type == enumClass || type.type == unitClass))
66 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, &value.i, string))
69 result = typeMismatch;
72 else if(type && (prop = eClass_FindProperty(type, "String", type.module)))
74 // TOFIX: Add more conversion property support... Expecting void * compatible here
75 value.p = ((void *(*)())(void *)prop.Set)(string);
79 else if(type && (type.type == structClass))
81 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, value.p, string))
84 result = typeMismatch;
90 result = typeMismatch;
97 if(type && eClass_IsDerived(type, class(Map)))
99 result = GetMap(type, (Map *)&array);
102 result = GetArray(type, &array);
104 if(result == success && type && eClass_IsDerived(type, class(Container)))
113 if(result != success)
114 result = typeMismatch;
117 else if(ch == '-' || isdigit(ch))
119 result = GetNumber(type, value);
123 void * object = value.p;
124 result = GetObject(type, &object);
127 if(type && type.type == structClass);
128 else if(type && (type.type == normalClass || type.type == noHeadClass || type.type == bitClass))
134 result = typeMismatch;
136 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, object);
144 while(c < sizeof(buffer)-1 && isalpha(ch))
147 if(!f.Getc(&ch)) break;
154 if(!strcmp(type.name, "bool"))
156 if(!strcmpi(buffer, "false")) value.i = 0;
157 else if(!strcmpi(buffer, "true")) value.i = 1;
159 result = typeMismatch;
161 else if(!strcmp(type.name, "SetBool"))
163 if(!strcmpi(buffer, "false")) value.i = SetBool::false;
164 else if(!strcmpi(buffer, "true")) value.i = SetBool::true;
166 result = typeMismatch;
168 else if(!strcmpi(buffer, "null"))
173 result = typeMismatch;
176 result = typeMismatch;
178 else if(ch == '}' || ch == ']')
183 JSONResult GetArray(Class type, Container * array)
185 JSONResult result = syntaxError;
190 *array = eInstance_New(type);
195 Class arrayType = null;
196 JSONResult itemResult;
198 if(eClass_IsDerived(type, class(Container)))
200 arrayType = type.templateArgs[0].dataTypeClass;
203 if(arrayType && arrayType.type == structClass)
204 value.p = new0 byte[arrayType.structSize];
205 itemResult = GetValue(arrayType, value);
206 if(itemResult == success)
208 // TODO: Verify the matching between template type and uint64
210 if(arrayType.type == structClass)
212 t = (uint64)(uintptr)value.p;
214 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
216 t = value.ui64; //*(uint64 *)&value.d;
218 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
220 t = value.ui; //f*(uint *)&value.f;
222 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
223 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
227 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
228 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
232 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
233 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
234 !strcmp(arrayType.dataTypeString, "int16"))
238 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
239 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
245 t = (uint64)(uintptr)value.p;
247 ((void *(*)(void *, uint64))(void *)array->Add)(*array, t);
249 if(arrayType && arrayType.type == structClass)
254 if(itemResult == typeMismatch)
257 PrintLn("Warning: Incompatible value for array value, expected ", (String)arrayType.name);
259 else if(itemResult == noItem)
265 if(result != syntaxError)
267 if(ch != ']' && ch != ',')
277 result = syntaxError;
285 JSONResult GetMap(Class type, Map * map)
287 JSONResult result = syntaxError;
292 Class mapNodeType = type.templateArgs[0].dataTypeClass;
293 Class keyType = mapNodeType.templateArgs[0].dataTypeClass;
294 Property keyProp = null;
295 if(keyType && !strcmp(keyType.dataTypeString, "char *"))
296 keyProp = eClass_FindProperty(mapNodeType, "key", mapNodeType.module);
298 *map = eInstance_New(type);
305 JSONResult itemResult;
307 itemResult = GetValue(mapNodeType, value);
308 if(itemResult == success)
310 String s = keyProp ? ((void * (*)(void *))(void *)keyProp.Get)(value.p) : null;
311 ((void *(*)(void *, uint64))(void *)map->Add)(*map, (uint64)(uintptr)value.p);
312 // Must free String keys here
317 if(itemResult == typeMismatch)
320 PrintLn("Warning: Incompatible value for array value, expected ", (String)mapNodeType.name);
322 else if(itemResult == noItem)
328 if(result != syntaxError)
330 if(ch != ']' && ch != ',')
340 result = syntaxError;
348 JSONResult GetString(String * string)
350 JSONResult result = syntaxError;
351 Array<char> buffer { minAllocSize = 256 };
352 bool escaped = false;
360 if(ch == '\\' && !escaped)
366 if(ch == 'b') ch = '\b';
367 else if(ch == 'f') ch = '\f';
368 else if(ch == 'n') ch = '\n';
369 else if(ch == 'r') ch = '\r';
370 else if(ch == 't') ch = '\t';
387 if(buffer.minAllocSize < buffer.count)
388 buffer.minAllocSize *= 2;
392 *string = CopyString(buffer.array);
396 if(ch != ',' && ch != '}')
401 public JSONResult GetObject(Class objectType, void ** object)
403 JSONResult result = syntaxError;
404 if(!objectType || objectType.type != structClass)
409 Class mapKeyClass = null, mapDataClass = null;
411 if(objectType && objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
413 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
414 mapDataClass = objectType.templateArgs[2].dataTypeClass;
418 if(objectType && (objectType.type == noHeadClass || objectType.type == normalClass))
420 *object = eInstance_New(objectType);
422 else if(objectType && objectType.type != structClass)
424 *object = eSystem_New(objectType.typeSize);
431 if(GetString(&string))
433 DataMember member = null;
434 Property prop = null;
441 string[0] = (char)tolower(string[0]);
442 if(mapKeyClass && !strcmp(string, "key"))
444 prop = eClass_FindProperty(objectType, "key", objectType.module);
448 else if(mapDataClass && !strcmp(string, "value"))
450 prop = eClass_FindProperty(objectType, "value", objectType.module);
455 member = eClass_FindDataMember(objectType, string, objectType.module, null, null);
458 type = eSystem_FindClass(__thisModule, member.dataTypeString);
460 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
462 offset = member._class.offset + member.offset;
466 prop = eClass_FindProperty(objectType, string, objectType.module);
469 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
471 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
474 PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
478 // Find Member in Object Class
482 if(type && type.type == structClass)
486 value.p = (byte *)*object + offset;
487 memset(value.p, 0, type.structSize);
491 value.p = new0 byte[type.structSize];
498 JSONResult itemResult = GetValue(type, value);
499 if(itemResult != syntaxError)
505 PrintLn("warning: Unresolved data type ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
507 else if(itemResult == success)
512 // TOFIX: How to swiftly handle classes with base data type?
513 if(type.type == structClass)
515 else if(type.type == normalClass || type.type == noHeadClass)
517 void ** ptr = (void**)((byte *)*object + offset);
518 if(eClass_IsDerived(type, class(Container)) && *ptr)
520 Container container = (Container)*ptr;
526 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
528 *(double *)((byte *)*object + offset) = value.d;
530 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
532 *(float *)((byte *)*object + offset) = value.f;
534 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
535 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
537 *(uint64 *)((byte *)*object + offset) = value.ui64;
539 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
540 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
542 *(int *)((byte *)*object + offset) = value.i;
544 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
545 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
546 !strcmp(type.dataTypeString, "int16"))
548 *(short *)((byte *)*object + offset) = value.s;
550 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
551 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
553 *(char *)((byte *)*object + offset) = value.c;
557 *(void **)((byte *)*object + offset) = value.p;
560 else if(prop && prop.Set)
562 if(!strcmp(type.dataTypeString, "char *"))
564 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
568 // TOFIX: How to swiftly handle classes with base data type?
569 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
571 ((void (*)(void *, double))(void *)prop.Set)(*object, value.d);
573 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
575 ((void (*)(void *, float))(void *)prop.Set)(*object, value.f);
577 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
578 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
580 ((void (*)(void *, uint64))(void *)prop.Set)(*object, value.ui64);
582 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
583 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
585 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
587 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
588 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
589 !strcmp(type.dataTypeString, "int16"))
591 ((void (*)(void *, short))(void *)prop.Set)(*object, value.s);
593 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
594 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
596 ((void (*)(void *, char))(void *)prop.Set)(*object, value.c);
600 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
606 PrintLn("Warning: Incompatible value for ", member ? (String)member.name : (String)prop.name,
607 ", expected ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
613 result = syntaxError;
615 if(prop && type.type == structClass)
621 else if(ch && ch != '}' && ch != ',')
622 result = syntaxError;
633 result = syntaxError;
641 JSONResult GetNumber(Class type, DataValue value)
643 JSONResult result = syntaxError;
646 while(c < sizeof(buffer)-1 && (ch == '-' || ch == '.' || tolower(ch) == 'e' || ch == '+' || isdigit(ch)))
649 if(!f.Getc(&ch)) break;
652 //if(strchr(buffer, '.'))
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 = strtoul(buffer, null, 10); // TOFIX: 64 bit support
684 value.i = 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("}");