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 && eClass_IsDerived(type, class(ColorAlpha)))
80 result = GetColorAlpha(string, value);
82 else if(type && (type.type == structClass))
84 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, value.p, string))
87 result = typeMismatch;
93 result = typeMismatch;
100 if(type && eClass_IsDerived(type, class(Map)))
102 result = GetMap(type, (Map *)&array);
105 result = GetArray(type, &array);
107 if(result == success && type && eClass_IsDerived(type, class(Container)))
116 if(result != success)
117 result = typeMismatch;
120 else if(ch == '-' || isdigit(ch))
122 result = GetNumber(type, value);
126 void * object = value.p;
127 result = GetObject(type, &object);
130 if(type && type.type == structClass);
131 else if(type && (type.type == normalClass || type.type == noHeadClass || type.type == bitClass))
137 result = typeMismatch;
139 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, object);
147 while(c < sizeof(buffer)-1 && isalpha(ch))
150 if(!f.Getc(&ch)) break;
157 if(!strcmp(type.name, "bool"))
159 if(!strcmpi(buffer, "false")) value.i = 0;
160 else if(!strcmpi(buffer, "true")) value.i = 1;
162 result = typeMismatch;
164 else if(!strcmp(type.name, "SetBool"))
166 if(!strcmpi(buffer, "false")) value.i = SetBool::false;
167 else if(!strcmpi(buffer, "true")) value.i = SetBool::true;
169 result = typeMismatch;
171 else if(!strcmpi(buffer, "null"))
173 if(type.type != structClass)
177 result = typeMismatch;
180 result = typeMismatch;
182 else if(ch == '}' || ch == ']')
187 JSONResult GetArray(Class type, Container * array)
189 JSONResult result = syntaxError;
194 *array = eInstance_New(type);
199 Class arrayType = null;
200 JSONResult itemResult;
202 if(eClass_IsDerived(type, class(Container)))
204 arrayType = type.templateArgs[0].dataTypeClass;
207 if(arrayType && arrayType.type == structClass)
208 value.p = new0 byte[arrayType.structSize];
209 itemResult = GetValue(arrayType, value);
210 if(itemResult == success)
212 // TODO: Verify the matching between template type and uint64
214 if(arrayType.type == structClass)
216 t = (uint64)(uintptr)value.p;
218 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
220 t = value.ui64; //*(uint64 *)&value.d;
222 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
224 t = value.ui; //f*(uint *)&value.f;
226 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
227 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
231 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
232 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
236 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
237 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
238 !strcmp(arrayType.dataTypeString, "int16"))
242 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
243 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
249 t = (uint64)(uintptr)value.p;
251 ((void *(*)(void *, uint64))(void *)array->Add)(*array, t);
253 if(arrayType && arrayType.type == structClass)
258 if(itemResult == typeMismatch)
261 PrintLn("Warning: Incompatible value for array value, expected ", (String)arrayType.name);
263 else if(itemResult == noItem)
269 if(result != syntaxError)
271 if(ch != ']' && ch != ',')
281 result = syntaxError;
289 JSONResult GetMap(Class type, Map * map)
291 JSONResult result = syntaxError;
296 Class mapNodeType = type.templateArgs[0].dataTypeClass;
297 Class keyType = mapNodeType.templateArgs[0].dataTypeClass;
298 Property keyProp = null;
299 if(keyType && !strcmp(keyType.dataTypeString, "char *"))
300 keyProp = eClass_FindProperty(mapNodeType, "key", mapNodeType.module);
302 *map = eInstance_New(type);
309 JSONResult itemResult;
311 itemResult = GetValue(mapNodeType, value);
312 if(itemResult == success)
314 String s = keyProp ? ((void * (*)(void *))(void *)keyProp.Get)(value.p) : null;
315 ((void *(*)(void *, uint64))(void *)map->Add)(*map, (uint64)(uintptr)value.p);
316 // Must free String keys here
321 if(itemResult == typeMismatch)
324 PrintLn("Warning: Incompatible value for array value, expected ", (String)mapNodeType.name);
326 else if(itemResult == noItem)
332 if(result != syntaxError)
334 if(ch != ']' && ch != ',')
344 result = syntaxError;
352 JSONResult GetString(String * string)
354 JSONResult result = syntaxError;
355 Array<char> buffer { minAllocSize = 256 };
356 bool escaped = false;
364 if(ch == '\\' && !escaped)
370 if(ch == 'b') ch = '\b';
371 else if(ch == 'f') ch = '\f';
372 else if(ch == 'n') ch = '\n';
373 else if(ch == 'r') ch = '\r';
374 else if(ch == 't') ch = '\t';
391 if(buffer.minAllocSize < buffer.count)
392 buffer.minAllocSize *= 2;
396 *string = CopyString(buffer.array);
400 if(ch != ',' && ch != '}')
405 public JSONResult GetObject(Class objectType, void ** object)
407 JSONResult result = syntaxError;
408 if(!objectType || objectType.type != structClass)
413 Class mapKeyClass = null, mapDataClass = null;
415 if(objectType && objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
417 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
418 mapDataClass = objectType.templateArgs[2].dataTypeClass;
422 if(objectType && (objectType.type == noHeadClass || objectType.type == normalClass))
424 *object = eInstance_New(objectType);
426 else if(objectType && objectType.type != structClass)
428 *object = eSystem_New(objectType.typeSize);
435 if(GetString(&string))
437 DataMember member = null;
438 Property prop = null;
445 string[0] = (char)tolower(string[0]);
446 if(mapKeyClass && !strcmp(string, "key"))
448 prop = eClass_FindProperty(objectType, "key", objectType.module);
452 else if(mapDataClass && !strcmp(string, "value"))
454 prop = eClass_FindProperty(objectType, "value", objectType.module);
459 member = eClass_FindDataMember(objectType, string, objectType.module, null, null);
462 type = eSystem_FindClass(__thisModule, member.dataTypeString);
464 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
466 offset = member._class.offset + member.offset;
470 prop = eClass_FindProperty(objectType, string, objectType.module);
473 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
475 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
478 PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
482 // Find Member in Object Class
486 if(type && type.type == structClass)
490 value.p = (byte *)*object + offset;
491 memset(value.p, 0, type.structSize);
495 value.p = new0 byte[type.structSize];
502 JSONResult itemResult = GetValue(type, value);
503 if(itemResult != syntaxError)
509 PrintLn("warning: Unresolved data type ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
511 else if(itemResult == success)
516 // TOFIX: How to swiftly handle classes with base data type?
517 if(type.type == structClass)
519 else if(type.type == normalClass || type.type == noHeadClass)
521 void ** ptr = (void**)((byte *)*object + offset);
522 if(eClass_IsDerived(type, class(Container)) && *ptr)
524 Container container = (Container)*ptr;
530 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
532 *(double *)((byte *)*object + offset) = value.d;
534 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
536 *(float *)((byte *)*object + offset) = value.f;
538 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
539 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
541 *(uint64 *)((byte *)*object + offset) = value.ui64;
543 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
544 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
546 *(int *)((byte *)*object + offset) = value.i;
548 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
549 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
550 !strcmp(type.dataTypeString, "int16"))
552 *(short *)((byte *)*object + offset) = value.s;
554 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
555 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
557 *(char *)((byte *)*object + offset) = value.c;
561 *(void **)((byte *)*object + offset) = value.p;
564 else if(prop && prop.Set)
566 if(!strcmp(type.dataTypeString, "char *"))
568 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
572 else if(type.type == enumClass || type.type == bitClass || type.type == unitClass || type.type == systemClass)
574 // TOFIX: How to swiftly handle classes with base data type?
575 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
577 ((void (*)(void *, double))(void *)prop.Set)(*object, value.d);
579 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
581 ((void (*)(void *, float))(void *)prop.Set)(*object, value.f);
583 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
584 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
586 ((void (*)(void *, uint64))(void *)prop.Set)(*object, value.ui64);
588 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
589 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
591 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
593 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
594 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
595 !strcmp(type.dataTypeString, "int16"))
597 ((void (*)(void *, short))(void *)prop.Set)(*object, value.s);
599 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
600 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
602 ((void (*)(void *, char))(void *)prop.Set)(*object, value.c);
606 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
611 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
617 PrintLn("Warning: Incompatible value for ", member ? (String)member.name : (String)prop.name,
618 ", expected ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
624 result = syntaxError;
626 if(prop && type.type == structClass)
632 else if(ch && ch != '}' && ch != ',')
633 result = syntaxError;
644 result = syntaxError;
652 JSONResult GetNumber(Class type, DataValue value)
654 JSONResult result = syntaxError;
657 while(c < sizeof(buffer)-1 && (ch == '-' || ch == '.' || tolower(ch) == 'e' || ch == '+' || isdigit(ch)))
660 if(!f.Getc(&ch)) break;
663 //if(strchr(buffer, '.'))
664 if(!type) return success;
666 // TOFIX: How to swiftly handle classes with base data type?
667 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
669 value.d = strtod(buffer, null);
672 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
674 value.f = (float)strtod(buffer, null);
677 // TOFIX: int64 looks for class long long?
678 //else if(type == class(int64) || !strcmp(type.dataTypeString, "int64"))
679 else if(!strcmp(type.dataTypeString, "int64"))
681 value.i64 = strtol(buffer, null, 10); // TOFIX: 64 bit support
684 else if(type == class(uint64) || !strcmp(type.dataTypeString, "uint64"))
686 value.ui64 = strtoul(buffer, null, 10); // TOFIX: 64 bit support
689 else if(type == class(uint) || !strcmp(type.dataTypeString, "unsigned int"))
691 value.ui = (uint)strtoul(buffer, null, 10); // TOFIX: 64 bit support
696 value.i = (int)strtol(buffer, null, 10);
700 if(result == success && type.type == unitClass)
702 // Convert to reference unit
704 for(prop = type.conversions.first; prop; prop = prop.next)
706 bool refProp = false;
708 if(!strcmp(prop.name, type.base.fullName))
710 else if( (c = eSystem_FindClass(type.module, prop.name) ) )
713 for(p = c.conversions.first; p; p = p.next)
715 if(!strcmp(p.name, type.base.fullName) && !p.Set && !p.Get)
724 if(prop.Set && prop.Get)
726 const String dts = type.base.dataTypeString;
727 if(!strcmp(dts, "double"))
728 value.d = ((double(*)(double))(void *)prop.Get)(value.d);
729 else if(!strcmp(dts, "float"))
730 value.f = ((float(*)(float))(void *)prop.Get)(value.f);
731 else if(!strcmp(dts, "int"))
732 value.i = ((int(*)(int))(void *)prop.Get)(value.i);
733 else if(!strcmp(dts, "int64"))
734 value.i64 = ((int64(*)(int64))(void *)prop.Get)(value.i64);
735 else if(!strcmp(dts, "unsigned int"))
736 value.ui = ((uint(*)(uint))(void *)prop.Get)(value.ui);
737 else if(!strcmp(dts, "uint64"))
738 value.ui64 = ((uint64(*)(uint64))(void *)prop.Get)(value.ui64);
748 JSONResult GetColorAlpha(String string, DataValue value)
750 ColorAlpha color = 0;
754 if(string[0] == '0' && string[1] == 'x')
755 color = (uint)strtoul(string, null, 0);
760 if((d = strchr(string, ',')))
762 a = (byte)atoi(string);
767 if(c.class::OnGetDataFromString(d))
773 color = (uint)strtoul(string, null, 16);
781 bool WriteMap(File f, Class type, Map map, int indent)
787 MapIterator it { map = map };
788 Class mapNodeClass = map._class.templateArgs[0].dataTypeClass;
794 MapNode n = (MapNode)it.pointer;
799 for(i = 0; i<indent; i++) f.Puts(" ");
800 _WriteJSONObject(f, mapNodeClass, n, indent);
804 for(i = 0; i<indent; i++) f.Puts(" ");
812 bool WriteArray(File f, Class type, Container array, int indent)
818 Iterator it { array };
819 Class arrayType = type.templateArgs[0].dataTypeClass;
826 uint64 t = ((uint64(*)(void *, void *))(void *)array.GetData)(array, it.pointer);
833 // TODO: Verify the matching between template type and uint64
834 if(arrayType.type == structClass)
836 value.p = (void *)(uintptr)t;
838 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
841 //value.d = *(double *)&t;
843 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
846 //value.f = *(float *)&t;
848 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
849 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
853 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
854 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
858 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
859 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
860 !strcmp(arrayType.dataTypeString, "int16"))
864 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
865 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
871 value.p = (void *)(uintptr)t;
873 for(i = 0; i<indent; i++) f.Puts(" ");
874 WriteValue(f, arrayType, value, indent);
878 for(i = 0; i<indent; i++) f.Puts(" ");
886 bool WriteNumber(File f, Class type, DataValue value, int indent)
889 bool needClass = false;
892 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
893 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.d, buffer, 0, &needClass);
894 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
895 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.f, buffer, null, &needClass);
896 else if(!strcmp(type.dataTypeString, "int64"))
897 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i64, buffer, null, &needClass);
898 else if(!strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64") || type.typeSize == sizeof(int64))
899 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui64, buffer, null, &needClass);
900 else if(!strcmp(type.dataTypeString, "int"))
901 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i, buffer, null, &needClass);
902 else if(!strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint") || type.typeSize == sizeof(int))
903 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui, buffer, null, &needClass);
904 else if(!strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "int16"))
905 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.s, buffer, null, &needClass);
906 else if(!strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") || type.typeSize == sizeof(short int))
907 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.us, buffer, null, &needClass);
908 else if(!strcmp(type.dataTypeString, "char"))
909 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.c, buffer, null, &needClass);
910 else if(!strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte") || type.typeSize == sizeof(byte))
911 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.uc, buffer, null, &needClass);
913 quote = (type.type == unitClass && ((buffer[0] != '.' && !isdigit(buffer[0])) || strchr(buffer, ' ')));
914 if(quote) f.Puts("\"");
916 if(quote) f.Puts("\"");
920 public bool WriteColorAlpha(File f, Class type, DataValue value, int indent)
923 char * string = buffer;
924 ColorAlpha color = value.i;
927 DefinedColor c = color;
931 a.class::OnGetString(buffer, null, null);
932 len = strlen(buffer);
938 if(!c.class::OnGetString(string, null, null))
939 sprintf(buffer, "0x%x", color);
946 bool WriteValue(File f, Class type, DataValue value, int indent)
948 if(!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *"))
955 //if(strchr(value.p, '\"') || strchr(value.p, '\\'))
960 char * string = value.p;
979 else if(b == sizeof(buffer)-2 || !ch)
982 if(ch) buffer[b] = 0;
996 else if(!strcmp(type.name, "bool"))
1003 else if(!strcmp(type.name, "SetBool"))
1005 if(value.i == SetBool::true)
1007 else if(value.i == SetBool::false)
1012 else if(type.type == enumClass)
1015 WriteNumber(f, type, value, indent);
1018 else if(eClass_IsDerived(type, class(Map)))
1020 WriteMap(f, type, value.p, indent);
1022 else if(eClass_IsDerived(type, class(Container)))
1024 WriteArray(f, type, value.p, indent);
1026 else if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
1028 _WriteJSONObject(f, type, value.p, indent);
1030 else if(eClass_IsDerived(type, class(ColorAlpha)))
1032 WriteColorAlpha(f, type, value, indent);
1034 else if(type.type == bitClass)
1037 dataType = eSystem_FindClass(__thisModule, type.dataTypeString);
1038 WriteNumber(f, dataType, value, indent);
1040 else if(type.type == systemClass || type.type == unitClass)
1042 WriteNumber(f, type, value, indent);
1047 public bool WriteJSONObject(File f, Class objectType, void * object, int indent)
1049 bool result = false;
1052 result = _WriteJSONObject(f, objectType, object, indent);
1058 static bool _WriteJSONObject(File f, Class objectType, void * object, int indent)
1062 const char * string = null;
1064 if(objectType._vTbl[__ecereVMethodID_class_OnGetString] != objectType.base._vTbl[__ecereVMethodID_class_OnGetString])
1068 string = ((const char *(*)())(void *)objectType._vTbl[__ecereVMethodID_class_OnGetString])(objectType, object, buffer, null, null);
1072 // TOCHECK: ProjectNode.ec why do we add quotes in OnGetString there?
1073 if(string[0] == '\"')
1086 bool isFirst = true;
1087 Class mapKeyClass = null, mapDataClass = null;
1089 List<Class> bases { };
1091 if(objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
1093 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
1094 mapDataClass = objectType.templateArgs[2].dataTypeClass;
1100 for(baseClass = objectType; baseClass; baseClass = baseClass.base)
1102 if(baseClass.isInstanceClass || !baseClass.base)
1104 bases.Insert(null, baseClass);
1107 for(baseClass : bases)
1109 for(prop = baseClass.membersAndProperties.first; prop; prop = prop.next)
1111 if(prop.memberAccess != publicAccess || (prop.isProperty && (!prop.Set || !prop.Get))) continue;
1114 if(!prop.conversion && (!prop.IsSet || prop.IsSet(object)))
1116 DataValue value { };
1119 if(mapKeyClass && !strcmp(prop.name, "key"))
1121 else if(mapDataClass && !strcmp(prop.name, "value"))
1122 type = mapDataClass;
1124 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
1126 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
1128 PrintLn("warning: Unresolved data type ", (String)prop.dataTypeString);
1131 // TOFIX: How to swiftly handle classes with base data type?
1132 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1134 value.d = ((double (*)(void *))(void *)prop.Get)(object);
1136 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1138 value.f = ((float (*)(void *))(void *)prop.Get)(object);
1140 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1141 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1143 value.ui64 = ((uint64 (*)(void *))(void *)prop.Get)(object);
1145 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1146 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1148 value.i = ((int (*)(void *))(void *)prop.Get)(object);
1150 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1151 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1152 !strcmp(type.dataTypeString, "int16"))
1154 value.s = ((short (*)(void *))(void *)prop.Get)(object);
1156 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1157 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1159 value.c = ((char (*)(void *))(void *)prop.Get)(object);
1161 else if(type.type == structClass)
1163 value.p = new0 byte[type.structSize];
1164 ((void (*)(void *, void *))(void *)prop.Get)(object, value.p);
1168 value.p = ((void *(*)(void *))(void *)prop.Get)(object);
1171 if(!isFirst) f.Puts(",\n");
1172 for(c = 0; c<indent; c++) f.Puts(" ");
1175 f.Putc((char)toupper(prop.name[0]));
1176 f.Puts(prop.name+1);
1178 WriteValue(f, type, value, indent);
1180 if(type.type == structClass)
1187 DataMember member = (DataMember)prop;
1188 DataValue value { };
1190 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
1192 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
1194 offset = member._class.offset + member.offset;
1198 if(type.type == normalClass || type.type == noHeadClass || type.type == structClass || !strcmp(type.name, "String"))
1200 if(type.type == structClass)
1201 value.p = (void *)((byte *)object + offset);
1203 value.p = *(void **)((byte *)object + offset);
1207 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1209 value.d = *(double *)((byte *)object + offset);
1211 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1213 value.f = *(float *)((byte *)object + offset);
1215 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1216 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1218 value.ui64 = *(uint64 *)((byte *)object + offset);
1220 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1221 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1223 value.i = *(int *)((byte *)object + offset);
1224 if(!strcmp(type.name, "bool") || type.type == enumClass)
1228 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1229 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1230 !strcmp(type.dataTypeString, "int16"))
1232 value.s = *(short *)((byte *)object + offset);
1234 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1235 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1237 value.c = *(char *)((byte *)object + offset);
1241 value.i = *(int *)((byte *)object + offset);
1244 if(!isFirst) f.Puts(",\n");
1245 for(c = 0; c<indent; c++) f.Puts(" ");
1248 f.Putc((char)toupper(member.name[0]));
1249 f.Puts(member.name+1);
1251 WriteValue(f, type, value, indent);
1262 for(c = 0; c<indent; c++) f.Puts(" "); f.Puts("}");