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 && eClass_IsDerived(type, class(ColorAlpha)))
81 result = GetColorAlpha(string, value);
83 else if(type && (type.type == structClass))
85 if(((bool (*)(void *, void *, const char *))(void *)type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(type, value.p, string))
88 result = typeMismatch;
94 result = typeMismatch;
101 if(type && eClass_IsDerived(type, class(Map)))
103 result = GetMap(type, (Map *)&array);
106 result = GetArray(type, &array);
108 if(result == success && type && eClass_IsDerived(type, class(Container)))
117 if(result != success)
118 result = typeMismatch;
121 else if(ch == '-' || isdigit(ch))
123 result = GetNumber(type, value);
127 void * object = value.p;
128 result = GetObject(type, &object);
131 if(type && type.type == structClass);
132 else if(type && (type.type == normalClass || type.type == noHeadClass || type.type == bitClass))
138 result = typeMismatch;
140 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, object);
148 while(c < sizeof(buffer)-1 && isalpha(ch))
151 if(!f.Getc(&ch)) break;
158 if(!strcmp(type.name, "bool"))
160 if(!strcmpi(buffer, "false")) value.i = 0;
161 else if(!strcmpi(buffer, "true")) value.i = 1;
163 result = typeMismatch;
165 else if(!strcmp(type.name, "SetBool"))
167 if(!strcmpi(buffer, "false")) value.i = SetBool::false;
168 else if(!strcmpi(buffer, "true")) value.i = SetBool::true;
170 result = typeMismatch;
172 else if(!strcmpi(buffer, "null"))
174 if(type.type != structClass)
178 result = typeMismatch;
181 result = typeMismatch;
183 else if(ch == '}' || ch == ']')
188 JSONResult GetArray(Class type, Container * array)
190 JSONResult result = syntaxError;
195 *array = eInstance_New(type);
200 Class arrayType = null;
201 JSONResult itemResult;
203 if(eClass_IsDerived(type, class(Container)))
205 arrayType = type.templateArgs[0].dataTypeClass;
208 if(arrayType && arrayType.type == structClass)
209 value.p = new0 byte[arrayType.structSize];
210 itemResult = GetValue(arrayType, value);
211 if(itemResult == success)
213 // TODO: Verify the matching between template type and uint64
215 if(arrayType.type == structClass)
217 t = (uint64)(uintptr)value.p;
219 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
221 t = value.ui64; //*(uint64 *)&value.d;
223 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
225 t = value.ui; //f*(uint *)&value.f;
227 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
228 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
232 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
233 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
237 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
238 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
239 !strcmp(arrayType.dataTypeString, "int16"))
243 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
244 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
250 t = (uint64)(uintptr)value.p;
252 ((void *(*)(void *, uint64))(void *)array->Add)(*array, t);
254 if(arrayType && arrayType.type == structClass)
259 if(itemResult == typeMismatch)
262 PrintLn("Warning: Incompatible value for array value, expected ", (String)arrayType.name);
264 else if(itemResult == noItem)
270 if(result != syntaxError)
272 if(ch != ']' && ch != ',')
282 result = syntaxError;
290 JSONResult GetMap(Class type, Map * map)
292 JSONResult result = syntaxError;
297 Class mapNodeType = type.templateArgs[0].dataTypeClass;
298 Class keyType = mapNodeType.templateArgs[0].dataTypeClass;
299 Property keyProp = null;
300 if(keyType && !strcmp(keyType.dataTypeString, "char *"))
301 keyProp = eClass_FindProperty(mapNodeType, "key", mapNodeType.module);
303 *map = eInstance_New(type);
310 JSONResult itemResult;
312 itemResult = GetValue(mapNodeType, value);
313 if(itemResult == success)
315 String s = keyProp ? ((void * (*)(void *))(void *)keyProp.Get)(value.p) : null;
316 ((void *(*)(void *, uint64))(void *)map->Add)(*map, (uint64)(uintptr)value.p);
317 // Must free String keys here
322 if(itemResult == typeMismatch)
325 PrintLn("Warning: Incompatible value for array value, expected ", (String)mapNodeType.name);
327 else if(itemResult == noItem)
333 if(result != syntaxError)
335 if(ch != ']' && ch != ',')
345 result = syntaxError;
353 JSONResult GetString(String * string)
355 JSONResult result = syntaxError;
356 Array<char> buffer { minAllocSize = 256 };
357 bool escaped = false;
365 if(ch == '\\' && !escaped)
371 if(ch == 'b') ch = '\b';
372 else if(ch == 'f') ch = '\f';
373 else if(ch == 'n') ch = '\n';
374 else if(ch == 'r') ch = '\r';
375 else if(ch == 't') ch = '\t';
392 if(buffer.minAllocSize < buffer.count)
393 buffer.minAllocSize *= 2;
397 *string = CopyString(buffer.array);
401 if(ch != ',' && ch != '}')
406 public JSONResult GetObject(Class objectType, void ** object)
408 JSONResult result = syntaxError;
409 if(!objectType || objectType.type != structClass)
414 Class mapKeyClass = null, mapDataClass = null;
416 if(objectType && objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
418 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
419 mapDataClass = objectType.templateArgs[2].dataTypeClass;
423 if(objectType && (objectType.type == noHeadClass || objectType.type == normalClass))
425 *object = eInstance_New(objectType);
427 else if(objectType && objectType.type != structClass)
429 *object = eSystem_New(objectType.typeSize);
436 if(GetString(&string))
438 DataMember member = null;
439 Property prop = null;
442 bool isTemplateArg = false;
447 string[0] = (char)tolower(string[0]);
448 if(mapKeyClass && !strcmp(string, "key"))
450 prop = eClass_FindProperty(objectType, "key", objectType.module);
452 isTemplateArg = true;
455 else if(mapDataClass && !strcmp(string, "value"))
457 prop = eClass_FindProperty(objectType, "value", objectType.module);
459 isTemplateArg = true;
463 member = eClass_FindDataMember(objectType, string, objectType.module, null, null);
466 type = eSystem_FindClass(__thisModule, member.dataTypeString);
468 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
470 offset = member._class.offset + member.offset;
474 prop = eClass_FindProperty(objectType, string, objectType.module);
477 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
479 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
482 PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
486 // Find Member in Object Class
490 if(type && type.type == structClass)
494 value.p = (byte *)*object + offset;
495 memset(value.p, 0, type.structSize);
499 value.p = new0 byte[type.structSize];
506 JSONResult itemResult = GetValue(type, value);
507 if(itemResult != syntaxError)
513 PrintLn("warning: Unresolved data type ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
515 else if(itemResult == success)
520 // TOFIX: How to swiftly handle classes with base data type?
521 if(type.type == structClass)
523 else if(type.type == normalClass || type.type == noHeadClass)
525 void ** ptr = (void**)((byte *)*object + offset);
526 if(eClass_IsDerived(type, class(Container)) && *ptr)
528 Container container = (Container)*ptr;
534 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
536 *(double *)((byte *)*object + offset) = value.d;
538 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
540 *(float *)((byte *)*object + offset) = value.f;
542 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
543 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
545 *(uint64 *)((byte *)*object + offset) = value.ui64;
547 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
548 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
550 *(int *)((byte *)*object + offset) = value.i;
552 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
553 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
554 !strcmp(type.dataTypeString, "int16"))
556 *(short *)((byte *)*object + offset) = value.s;
558 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
559 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
561 *(char *)((byte *)*object + offset) = value.c;
565 *(void **)((byte *)*object + offset) = value.p;
568 else if(prop && prop.Set)
570 if(!strcmp(type.dataTypeString, "char *"))
572 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
576 else if(type.type == enumClass || type.type == bitClass || type.type == unitClass || type.type == systemClass)
578 // TOFIX: How to swiftly handle classes with base data type?
579 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
581 ((void (*)(void *, double))(void *)prop.Set)(*object, value.d);
583 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
585 ((void (*)(void *, float))(void *)prop.Set)(*object, value.f);
587 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
588 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
590 ((void (*)(void *, uint64))(void *)prop.Set)(*object, value.ui64);
592 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
593 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
595 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
597 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
598 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
599 !strcmp(type.dataTypeString, "int16"))
601 ((void (*)(void *, short))(void *)prop.Set)(*object, value.s);
603 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
604 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
606 ((void (*)(void *, char))(void *)prop.Set)(*object, value.c);
610 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
616 ((void (*)(void *, uint64))(void *)prop.Set)(*object, (uint64)(uintptr)value.p);
618 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
624 PrintLn("Warning: Incompatible value for ", member ? (String)member.name : (String)prop.name,
625 ", expected ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
631 result = syntaxError;
633 if(prop && type.type == structClass)
639 else if(ch && ch != '}' && ch != ',')
640 result = syntaxError;
651 result = syntaxError;
659 JSONResult GetNumber(Class type, DataValue value)
661 JSONResult result = syntaxError;
664 while(c < sizeof(buffer)-1 && (ch == '-' || ch == '.' || tolower(ch) == 'e' || ch == '+' || isdigit(ch)))
667 if(!f.Getc(&ch)) break;
670 //if(strchr(buffer, '.'))
671 if(!type) return success;
673 // TOFIX: How to swiftly handle classes with base data type?
674 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
676 value.d = strtod(buffer, null);
679 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
681 value.f = (float)strtod(buffer, null);
684 // TOFIX: int64 looks for class long long?
685 //else if(type == class(int64) || !strcmp(type.dataTypeString, "int64"))
686 else if(!strcmp(type.dataTypeString, "int64"))
688 value.i64 = strtol(buffer, null, 10); // TOFIX: 64 bit support
691 else if(type == class(uint64) || !strcmp(type.dataTypeString, "uint64"))
693 value.ui64 = strtoul(buffer, null, 10); // TOFIX: 64 bit support
696 else if(type == class(uint) || !strcmp(type.dataTypeString, "unsigned int"))
698 value.ui = (uint)strtoul(buffer, null, 10); // TOFIX: 64 bit support
703 value.i = (int)strtol(buffer, null, 10);
707 if(result == success && type.type == unitClass)
709 // Convert to reference unit
711 for(prop = type.conversions.first; prop; prop = prop.next)
713 bool refProp = false;
715 if(!strcmp(prop.name, type.base.fullName))
717 else if( (c = eSystem_FindClass(type.module, prop.name) ) )
720 for(p = c.conversions.first; p; p = p.next)
722 if(!strcmp(p.name, type.base.fullName) && !p.Set && !p.Get)
731 if(prop.Set && prop.Get)
733 const String dts = type.base.dataTypeString;
734 if(!strcmp(dts, "double"))
735 value.d = ((double(*)(double))(void *)prop.Get)(value.d);
736 else if(!strcmp(dts, "float"))
737 value.f = ((float(*)(float))(void *)prop.Get)(value.f);
738 else if(!strcmp(dts, "int"))
739 value.i = ((int(*)(int))(void *)prop.Get)(value.i);
740 else if(!strcmp(dts, "int64"))
741 value.i64 = ((int64(*)(int64))(void *)prop.Get)(value.i64);
742 else if(!strcmp(dts, "unsigned int"))
743 value.ui = ((uint(*)(uint))(void *)prop.Get)(value.ui);
744 else if(!strcmp(dts, "uint64"))
745 value.ui64 = ((uint64(*)(uint64))(void *)prop.Get)(value.ui64);
755 JSONResult GetColorAlpha(String string, DataValue value)
757 ColorAlpha color = 0;
761 if(string[0] == '0' && string[1] == 'x')
762 color = (uint)strtoul(string, null, 0);
767 if((d = strchr(string, ',')))
769 a = (byte)atoi(string);
774 if(c.class::OnGetDataFromString(d))
780 color = (uint)strtoul(string, null, 16);
788 bool WriteMap(File f, Class type, Map map, int indent)
794 MapIterator it { map = map };
795 Class mapNodeClass = map._class.templateArgs[0].dataTypeClass;
801 MapNode n = (MapNode)it.pointer;
806 for(i = 0; i<indent; i++) f.Puts(" ");
807 _WriteJSONObject(f, mapNodeClass, n, indent);
811 for(i = 0; i<indent; i++) f.Puts(" ");
819 bool WriteArray(File f, Class type, Container array, int indent)
825 Iterator it { array };
826 Class arrayType = type.templateArgs[0].dataTypeClass;
833 uint64 t = ((uint64(*)(void *, void *))(void *)array.GetData)(array, it.pointer);
840 // TODO: Verify the matching between template type and uint64
841 if(arrayType.type == structClass)
843 value.p = (void *)(uintptr)t;
845 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
848 //value.d = *(double *)&t;
850 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
853 //value.f = *(float *)&t;
855 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
856 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
860 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
861 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
865 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
866 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
867 !strcmp(arrayType.dataTypeString, "int16"))
871 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
872 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
878 value.p = (void *)(uintptr)t;
880 for(i = 0; i<indent; i++) f.Puts(" ");
881 WriteValue(f, arrayType, value, indent);
885 for(i = 0; i<indent; i++) f.Puts(" ");
893 bool WriteNumber(File f, Class type, DataValue value, int indent)
896 bool needClass = false;
899 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
900 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.d, buffer, 0, &needClass);
901 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
902 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.f, buffer, null, &needClass);
903 else if(!strcmp(type.dataTypeString, "int64"))
904 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i64, buffer, null, &needClass);
905 else if(!strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64") || type.typeSize == sizeof(int64))
906 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui64, buffer, null, &needClass);
907 else if(!strcmp(type.dataTypeString, "int"))
908 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i, buffer, null, &needClass);
909 else if(!strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint") || type.typeSize == sizeof(int))
910 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui, buffer, null, &needClass);
911 else if(!strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "int16"))
912 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.s, buffer, null, &needClass);
913 else if(!strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") || type.typeSize == sizeof(short int))
914 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.us, buffer, null, &needClass);
915 else if(!strcmp(type.dataTypeString, "char"))
916 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.c, buffer, null, &needClass);
917 else if(!strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte") || type.typeSize == sizeof(byte))
918 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.uc, buffer, null, &needClass);
920 quote = (type.type == unitClass && ((buffer[0] != '.' && !isdigit(buffer[0])) || strchr(buffer, ' ')));
921 if(quote) f.Puts("\"");
923 if(quote) f.Puts("\"");
927 public bool WriteColorAlpha(File f, Class type, DataValue value, int indent)
930 char * string = buffer;
931 ColorAlpha color = value.i;
934 DefinedColor c = color;
938 a.class::OnGetString(buffer, null, null);
939 len = strlen(buffer);
945 if(!c.class::OnGetString(string, null, null))
946 sprintf(buffer, "0x%x", color);
953 bool WriteValue(File f, Class type, DataValue value, int indent)
955 if(!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *"))
962 //if(strchr(value.p, '\"') || strchr(value.p, '\\'))
967 char * string = value.p;
986 else if(b == sizeof(buffer)-2 || !ch)
989 if(ch) buffer[b] = 0;
1003 else if(!strcmp(type.name, "bool"))
1010 else if(!strcmp(type.name, "SetBool"))
1012 if(value.i == SetBool::true)
1014 else if(value.i == SetBool::false)
1019 else if(type.type == enumClass)
1022 WriteNumber(f, type, value, indent);
1025 else if(eClass_IsDerived(type, class(Map)))
1027 WriteMap(f, type, value.p, indent);
1029 else if(eClass_IsDerived(type, class(Container)))
1031 WriteArray(f, type, value.p, indent);
1033 else if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
1035 _WriteJSONObject(f, type, value.p, indent);
1037 else if(eClass_IsDerived(type, class(ColorAlpha)))
1039 WriteColorAlpha(f, type, value, indent);
1041 else if(type.type == bitClass)
1044 dataType = eSystem_FindClass(__thisModule, type.dataTypeString);
1045 WriteNumber(f, dataType, value, indent);
1047 else if(type.type == systemClass || type.type == unitClass)
1049 WriteNumber(f, type, value, indent);
1054 public bool WriteJSONObject(File f, Class objectType, void * object, int indent)
1056 bool result = false;
1059 result = _WriteJSONObject(f, objectType, object, indent);
1065 static bool _WriteJSONObject(File f, Class objectType, void * object, int indent)
1069 const char * string = null;
1071 if(objectType._vTbl[__ecereVMethodID_class_OnGetString] != objectType.base._vTbl[__ecereVMethodID_class_OnGetString])
1075 string = ((const char *(*)())(void *)objectType._vTbl[__ecereVMethodID_class_OnGetString])(objectType, object, buffer, null, null);
1079 // TOCHECK: ProjectNode.ec why do we add quotes in OnGetString there?
1080 if(string[0] == '\"')
1093 bool isFirst = true;
1094 Class mapKeyClass = null, mapDataClass = null;
1096 List<Class> bases { };
1098 if(objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
1100 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
1101 mapDataClass = objectType.templateArgs[2].dataTypeClass;
1107 for(baseClass = objectType; baseClass; baseClass = baseClass.base)
1109 if(baseClass.isInstanceClass || !baseClass.base)
1111 bases.Insert(null, baseClass);
1114 for(baseClass : bases)
1116 for(prop = baseClass.membersAndProperties.first; prop; prop = prop.next)
1118 if(prop.memberAccess != publicAccess || (prop.isProperty && (!prop.Set || !prop.Get))) continue;
1121 if(!prop.conversion && (!prop.IsSet || prop.IsSet(object)))
1123 DataValue value { };
1124 bool isTemplateArg = false;
1127 if(mapKeyClass && !strcmp(prop.name, "key"))
1129 isTemplateArg = true;
1132 else if(mapDataClass && !strcmp(prop.name, "value"))
1134 isTemplateArg = true;
1135 type = mapDataClass;
1138 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
1141 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
1143 PrintLn("warning: Unresolved data type ", (String)prop.dataTypeString);
1146 if(type.type == enumClass || type.type == bitClass || type.type == unitClass || type.type == systemClass)
1148 // TOFIX: How to swiftly handle classes with base data type?
1149 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1151 value.d = ((double (*)(void *))(void *)prop.Get)(object);
1153 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1155 value.f = ((float (*)(void *))(void *)prop.Get)(object);
1157 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1158 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1160 value.ui64 = ((uint64 (*)(void *))(void *)prop.Get)(object);
1162 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1163 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1165 value.i = ((int (*)(void *))(void *)prop.Get)(object);
1167 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1168 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1169 !strcmp(type.dataTypeString, "int16"))
1171 value.s = ((short (*)(void *))(void *)prop.Get)(object);
1173 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1174 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1176 value.c = ((char (*)(void *))(void *)prop.Get)(object);
1179 else if(type.type == structClass)
1181 value.p = new0 byte[type.structSize];
1182 ((void (*)(void *, void *))(void *)prop.Get)(object, value.p);
1187 value.p = (void *)(uintptr)((uint64 (*)(void *))(void *)prop.Get)(object);
1189 value.p = ((void *(*)(void *))(void *)prop.Get)(object);
1192 if(!isFirst) f.Puts(",\n");
1193 for(c = 0; c<indent; c++) f.Puts(" ");
1196 f.Putc((char)toupper(prop.name[0]));
1197 f.Puts(prop.name+1);
1199 WriteValue(f, type, value, indent);
1201 if(type.type == structClass)
1208 DataMember member = (DataMember)prop;
1209 DataValue value { };
1211 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
1213 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
1215 offset = member._class.offset + member.offset;
1219 if(type.type == normalClass || type.type == noHeadClass || type.type == structClass || !strcmp(type.name, "String"))
1221 if(type.type == structClass)
1222 value.p = (void *)((byte *)object + offset);
1224 value.p = *(void **)((byte *)object + offset);
1228 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1230 value.d = *(double *)((byte *)object + offset);
1232 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1234 value.f = *(float *)((byte *)object + offset);
1236 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1237 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1239 value.ui64 = *(uint64 *)((byte *)object + offset);
1241 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1242 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1244 value.i = *(int *)((byte *)object + offset);
1245 if(!strcmp(type.name, "bool") || type.type == enumClass)
1249 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1250 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1251 !strcmp(type.dataTypeString, "int16"))
1253 value.s = *(short *)((byte *)object + offset);
1255 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1256 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1258 value.c = *(char *)((byte *)object + offset);
1262 value.i = *(int *)((byte *)object + offset);
1265 if(!isFirst) f.Puts(",\n");
1266 for(c = 0; c<indent; c++) f.Puts(" ");
1269 f.Putc((char)toupper(member.name[0]));
1270 f.Puts(member.name+1);
1272 WriteValue(f, type, value, indent);
1283 for(c = 0; c<indent; c++) f.Puts(" "); f.Puts("}");