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;
441 bool isTemplateArg = false;
446 string[0] = (char)tolower(string[0]);
447 if(mapKeyClass && !strcmp(string, "key"))
449 prop = eClass_FindProperty(objectType, "key", objectType.module);
451 isTemplateArg = true;
454 else if(mapDataClass && !strcmp(string, "value"))
456 prop = eClass_FindProperty(objectType, "value", objectType.module);
458 isTemplateArg = true;
462 member = eClass_FindDataMember(objectType, string, objectType.module, null, null);
465 type = eSystem_FindClass(__thisModule, member.dataTypeString);
467 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
469 offset = member._class.offset + member.offset;
473 prop = eClass_FindProperty(objectType, string, objectType.module);
476 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
478 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
481 PrintLn("Warning: member ", string, " not found in class ", (String)objectType.name);
485 // Find Member in Object Class
489 if(type && type.type == structClass)
493 value.p = (byte *)*object + offset;
494 memset(value.p, 0, type.structSize);
498 value.p = new0 byte[type.structSize];
505 JSONResult itemResult = GetValue(type, value);
506 if(itemResult != syntaxError)
512 PrintLn("warning: Unresolved data type ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
514 else if(itemResult == success)
519 // TOFIX: How to swiftly handle classes with base data type?
520 if(type.type == structClass)
522 else if(type.type == normalClass || type.type == noHeadClass)
524 void ** ptr = (void**)((byte *)*object + offset);
525 if(eClass_IsDerived(type, class(Container)) && *ptr)
527 Container container = (Container)*ptr;
533 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
535 *(double *)((byte *)*object + offset) = value.d;
537 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
539 *(float *)((byte *)*object + offset) = value.f;
541 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
542 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
544 *(uint64 *)((byte *)*object + offset) = value.ui64;
546 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
547 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
549 *(int *)((byte *)*object + offset) = value.i;
551 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
552 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
553 !strcmp(type.dataTypeString, "int16"))
555 *(short *)((byte *)*object + offset) = value.s;
557 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
558 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
560 *(char *)((byte *)*object + offset) = value.c;
564 *(void **)((byte *)*object + offset) = value.p;
567 else if(prop && prop.Set)
569 if(!strcmp(type.dataTypeString, "char *"))
571 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
575 else if(type.type == enumClass || type.type == bitClass || type.type == unitClass || type.type == systemClass)
577 // TOFIX: How to swiftly handle classes with base data type?
578 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
580 ((void (*)(void *, double))(void *)prop.Set)(*object, value.d);
582 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
584 ((void (*)(void *, float))(void *)prop.Set)(*object, value.f);
586 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
587 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
589 ((void (*)(void *, uint64))(void *)prop.Set)(*object, value.ui64);
591 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
592 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
594 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
596 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
597 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
598 !strcmp(type.dataTypeString, "int16"))
600 ((void (*)(void *, short))(void *)prop.Set)(*object, value.s);
602 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
603 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
605 ((void (*)(void *, char))(void *)prop.Set)(*object, value.c);
609 ((void (*)(void *, int))(void *)prop.Set)(*object, value.i);
615 ((void (*)(void *, uint64))(void *)prop.Set)(*object, (uint64)(uintptr)value.p);
617 ((void (*)(void *, void *))(void *)prop.Set)(*object, value.p);
623 PrintLn("Warning: Incompatible value for ", member ? (String)member.name : (String)prop.name,
624 ", expected ", member ? (String)member.dataTypeString : (String)prop.dataTypeString);
630 result = syntaxError;
632 if(prop && type.type == structClass)
638 else if(ch && ch != '}' && ch != ',')
639 result = syntaxError;
650 result = syntaxError;
658 JSONResult GetNumber(Class type, DataValue value)
660 JSONResult result = syntaxError;
663 while(c < sizeof(buffer)-1 && (ch == '-' || ch == '.' || tolower(ch) == 'e' || ch == '+' || isdigit(ch)))
666 if(!f.Getc(&ch)) break;
669 //if(strchr(buffer, '.'))
670 if(!type) return success;
672 // TOFIX: How to swiftly handle classes with base data type?
673 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
675 value.d = strtod(buffer, null);
678 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
680 value.f = (float)strtod(buffer, null);
683 // TOFIX: int64 looks for class long long?
684 //else if(type == class(int64) || !strcmp(type.dataTypeString, "int64"))
685 else if(!strcmp(type.dataTypeString, "int64"))
687 value.i64 = strtol(buffer, null, 10); // TOFIX: 64 bit support
690 else if(type == class(uint64) || !strcmp(type.dataTypeString, "uint64"))
692 value.ui64 = strtoul(buffer, null, 10); // TOFIX: 64 bit support
695 else if(type == class(uint) || !strcmp(type.dataTypeString, "unsigned int"))
697 value.ui = (uint)strtoul(buffer, null, 10); // TOFIX: 64 bit support
702 value.i = (int)strtol(buffer, null, 10);
706 if(result == success && type.type == unitClass)
708 // Convert to reference unit
710 for(prop = type.conversions.first; prop; prop = prop.next)
712 bool refProp = false;
714 if(!strcmp(prop.name, type.base.fullName))
716 else if( (c = eSystem_FindClass(type.module, prop.name) ) )
719 for(p = c.conversions.first; p; p = p.next)
721 if(!strcmp(p.name, type.base.fullName) && !p.Set && !p.Get)
730 if(prop.Set && prop.Get)
732 const String dts = type.base.dataTypeString;
733 if(!strcmp(dts, "double"))
734 value.d = ((double(*)(double))(void *)prop.Get)(value.d);
735 else if(!strcmp(dts, "float"))
736 value.f = ((float(*)(float))(void *)prop.Get)(value.f);
737 else if(!strcmp(dts, "int"))
738 value.i = ((int(*)(int))(void *)prop.Get)(value.i);
739 else if(!strcmp(dts, "int64"))
740 value.i64 = ((int64(*)(int64))(void *)prop.Get)(value.i64);
741 else if(!strcmp(dts, "unsigned int"))
742 value.ui = ((uint(*)(uint))(void *)prop.Get)(value.ui);
743 else if(!strcmp(dts, "uint64"))
744 value.ui64 = ((uint64(*)(uint64))(void *)prop.Get)(value.ui64);
754 JSONResult GetColorAlpha(String string, DataValue value)
756 ColorAlpha color = 0;
760 if(string[0] == '0' && string[1] == 'x')
761 color = (uint)strtoul(string, null, 0);
766 if((d = strchr(string, ',')))
768 a = (byte)atoi(string);
773 if(c.class::OnGetDataFromString(d))
779 color = (uint)strtoul(string, null, 16);
787 bool WriteMap(File f, Class type, Map map, int indent)
793 MapIterator it { map = map };
794 Class mapNodeClass = map._class.templateArgs[0].dataTypeClass;
800 MapNode n = (MapNode)it.pointer;
805 for(i = 0; i<indent; i++) f.Puts(" ");
806 _WriteJSONObject(f, mapNodeClass, n, indent);
810 for(i = 0; i<indent; i++) f.Puts(" ");
818 bool WriteArray(File f, Class type, Container array, int indent)
824 Iterator it { array };
825 Class arrayType = type.templateArgs[0].dataTypeClass;
832 uint64 t = ((uint64(*)(void *, void *))(void *)array.GetData)(array, it.pointer);
839 // TODO: Verify the matching between template type and uint64
840 if(arrayType.type == structClass)
842 value.p = (void *)(uintptr)t;
844 else if(arrayType == class(double) || !strcmp(arrayType.dataTypeString, "double"))
847 //value.d = *(double *)&t;
849 else if(arrayType == class(float) || !strcmp(arrayType.dataTypeString, "float"))
852 //value.f = *(float *)&t;
854 else if(arrayType.typeSize == sizeof(int64) || !strcmp(arrayType.dataTypeString, "int64") ||
855 !strcmp(arrayType.dataTypeString, "unsigned int64") || !strcmp(arrayType.dataTypeString, "uint64"))
859 else if(arrayType.typeSize == sizeof(int) || !strcmp(arrayType.dataTypeString, "int") ||
860 !strcmp(arrayType.dataTypeString, "unsigned int") || !strcmp(arrayType.dataTypeString, "uint"))
864 else if(arrayType.typeSize == sizeof(short int) || !strcmp(arrayType.dataTypeString, "short") ||
865 !strcmp(arrayType.dataTypeString, "unsigned short") || !strcmp(arrayType.dataTypeString, "uint16") ||
866 !strcmp(arrayType.dataTypeString, "int16"))
870 else if(arrayType.typeSize == sizeof(byte) || !strcmp(arrayType.dataTypeString, "char") ||
871 !strcmp(arrayType.dataTypeString, "unsigned char") || !strcmp(arrayType.dataTypeString, "byte"))
877 value.p = (void *)(uintptr)t;
879 for(i = 0; i<indent; i++) f.Puts(" ");
880 WriteValue(f, arrayType, value, indent);
884 for(i = 0; i<indent; i++) f.Puts(" ");
892 bool WriteNumber(File f, Class type, DataValue value, int indent)
895 bool needClass = false;
898 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
899 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.d, buffer, 0, &needClass);
900 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
901 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.f, buffer, null, &needClass);
902 else if(!strcmp(type.dataTypeString, "int64"))
903 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i64, buffer, null, &needClass);
904 else if(!strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64") || type.typeSize == sizeof(int64))
905 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui64, buffer, null, &needClass);
906 else if(!strcmp(type.dataTypeString, "int"))
907 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.i, buffer, null, &needClass);
908 else if(!strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint") || type.typeSize == sizeof(int))
909 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.ui, buffer, null, &needClass);
910 else if(!strcmp(type.dataTypeString, "short") || !strcmp(type.dataTypeString, "int16"))
911 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.s, buffer, null, &needClass);
912 else if(!strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") || type.typeSize == sizeof(short int))
913 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.us, buffer, null, &needClass);
914 else if(!strcmp(type.dataTypeString, "char"))
915 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.c, buffer, null, &needClass);
916 else if(!strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte") || type.typeSize == sizeof(byte))
917 ((const char *(*)(void *, void *, char *, void *, bool *))(void *)type._vTbl[__ecereVMethodID_class_OnGetString])(type, &value.uc, buffer, null, &needClass);
919 quote = (type.type == unitClass && ((buffer[0] != '.' && !isdigit(buffer[0])) || strchr(buffer, ' ')));
920 if(quote) f.Puts("\"");
922 if(quote) f.Puts("\"");
926 public bool WriteColorAlpha(File f, Class type, DataValue value, int indent)
929 char * string = buffer;
930 ColorAlpha color = value.i;
933 DefinedColor c = color;
937 a.class::OnGetString(buffer, null, null);
938 len = strlen(buffer);
944 if(!c.class::OnGetString(string, null, null))
945 sprintf(buffer, "0x%x", color);
952 bool WriteValue(File f, Class type, DataValue value, int indent)
954 if(!strcmp(type.name, "String") || !strcmp(type.dataTypeString, "char *"))
961 //if(strchr(value.p, '\"') || strchr(value.p, '\\'))
966 char * string = value.p;
985 else if(b == sizeof(buffer)-2 || !ch)
988 if(ch) buffer[b] = 0;
1002 else if(!strcmp(type.name, "bool"))
1009 else if(!strcmp(type.name, "SetBool"))
1011 if(value.i == SetBool::true)
1013 else if(value.i == SetBool::false)
1018 else if(type.type == enumClass)
1021 WriteNumber(f, type, value, indent);
1024 else if(eClass_IsDerived(type, class(Map)))
1026 WriteMap(f, type, value.p, indent);
1028 else if(eClass_IsDerived(type, class(Container)))
1030 WriteArray(f, type, value.p, indent);
1032 else if(type.type == normalClass || type.type == noHeadClass || type.type == structClass)
1034 _WriteJSONObject(f, type, value.p, indent);
1036 else if(eClass_IsDerived(type, class(ColorAlpha)))
1038 WriteColorAlpha(f, type, value, indent);
1040 else if(type.type == bitClass)
1043 dataType = eSystem_FindClass(__thisModule, type.dataTypeString);
1044 WriteNumber(f, dataType, value, indent);
1046 else if(type.type == systemClass || type.type == unitClass)
1048 WriteNumber(f, type, value, indent);
1053 public bool WriteJSONObject(File f, Class objectType, void * object, int indent)
1055 bool result = false;
1058 result = _WriteJSONObject(f, objectType, object, indent);
1064 static bool _WriteJSONObject(File f, Class objectType, void * object, int indent)
1068 const char * string = null;
1070 if(objectType._vTbl[__ecereVMethodID_class_OnGetString] != objectType.base._vTbl[__ecereVMethodID_class_OnGetString])
1074 string = ((const char *(*)())(void *)objectType._vTbl[__ecereVMethodID_class_OnGetString])(objectType, object, buffer, null, null);
1078 // TOCHECK: ProjectNode.ec why do we add quotes in OnGetString there?
1079 if(string[0] == '\"')
1092 bool isFirst = true;
1093 Class mapKeyClass = null, mapDataClass = null;
1095 List<Class> bases { };
1097 if(objectType.templateClass && eClass_IsDerived(objectType.templateClass, class(MapNode)))
1099 mapKeyClass = objectType.templateArgs[0].dataTypeClass;
1100 mapDataClass = objectType.templateArgs[2].dataTypeClass;
1106 for(baseClass = objectType; baseClass; baseClass = baseClass.base)
1108 if(baseClass.isInstanceClass || !baseClass.base)
1110 bases.Insert(null, baseClass);
1113 for(baseClass : bases)
1115 for(prop = baseClass.membersAndProperties.first; prop; prop = prop.next)
1117 if(prop.memberAccess != publicAccess || (prop.isProperty && (!prop.Set || !prop.Get))) continue;
1120 if(!prop.conversion && (!prop.IsSet || prop.IsSet(object)))
1122 DataValue value { };
1123 bool isTemplateArg = false;
1126 if(mapKeyClass && !strcmp(prop.name, "key"))
1128 isTemplateArg = true;
1131 else if(mapDataClass && !strcmp(prop.name, "value"))
1133 isTemplateArg = true;
1134 type = mapDataClass;
1137 type = eSystem_FindClass(__thisModule, prop.dataTypeString);
1140 type = eSystem_FindClass(__thisModule.application, prop.dataTypeString);
1142 PrintLn("warning: Unresolved data type ", (String)prop.dataTypeString);
1145 if(type.type == enumClass || type.type == bitClass || type.type == unitClass || type.type == systemClass)
1147 // TOFIX: How to swiftly handle classes with base data type?
1148 if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1150 value.d = ((double (*)(void *))(void *)prop.Get)(object);
1152 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1154 value.f = ((float (*)(void *))(void *)prop.Get)(object);
1156 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1157 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1159 value.ui64 = ((uint64 (*)(void *))(void *)prop.Get)(object);
1161 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1162 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1164 value.i = ((int (*)(void *))(void *)prop.Get)(object);
1166 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1167 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1168 !strcmp(type.dataTypeString, "int16"))
1170 value.s = ((short (*)(void *))(void *)prop.Get)(object);
1172 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1173 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1175 value.c = ((char (*)(void *))(void *)prop.Get)(object);
1178 else if(type.type == structClass)
1180 value.p = new0 byte[type.structSize];
1181 ((void (*)(void *, void *))(void *)prop.Get)(object, value.p);
1186 value.p = (void *)(uintptr)((uint64 (*)(void *))(void *)prop.Get)(object);
1188 value.p = ((void *(*)(void *))(void *)prop.Get)(object);
1191 if(!isFirst) f.Puts(",\n");
1192 for(c = 0; c<indent; c++) f.Puts(" ");
1195 f.Putc((char)toupper(prop.name[0]));
1196 f.Puts(prop.name+1);
1198 WriteValue(f, type, value, indent);
1200 if(type.type == structClass)
1207 DataMember member = (DataMember)prop;
1208 DataValue value { };
1210 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
1212 type = eSystem_FindClass(__thisModule.application, member.dataTypeString);
1214 offset = member._class.offset + member.offset;
1218 if(type.type == normalClass || type.type == noHeadClass || type.type == structClass || !strcmp(type.name, "String"))
1220 if(type.type == structClass)
1221 value.p = (void *)((byte *)object + offset);
1223 value.p = *(void **)((byte *)object + offset);
1227 else if(type == class(double) || !strcmp(type.dataTypeString, "double"))
1229 value.d = *(double *)((byte *)object + offset);
1231 else if(type == class(float) || !strcmp(type.dataTypeString, "float"))
1233 value.f = *(float *)((byte *)object + offset);
1235 else if(type.typeSize == sizeof(int64) || !strcmp(type.dataTypeString, "int64") ||
1236 !strcmp(type.dataTypeString, "unsigned int64") || !strcmp(type.dataTypeString, "uint64"))
1238 value.ui64 = *(uint64 *)((byte *)object + offset);
1240 else if(type.typeSize == sizeof(int) || !strcmp(type.dataTypeString, "int") ||
1241 !strcmp(type.dataTypeString, "unsigned int") || !strcmp(type.dataTypeString, "uint"))
1243 value.i = *(int *)((byte *)object + offset);
1244 if(!strcmp(type.name, "bool") || type.type == enumClass)
1248 else if(type.typeSize == sizeof(short int) || !strcmp(type.dataTypeString, "short") ||
1249 !strcmp(type.dataTypeString, "unsigned short") || !strcmp(type.dataTypeString, "uint16") ||
1250 !strcmp(type.dataTypeString, "int16"))
1252 value.s = *(short *)((byte *)object + offset);
1254 else if(type.typeSize == sizeof(byte) || !strcmp(type.dataTypeString, "char") ||
1255 !strcmp(type.dataTypeString, "unsigned char") || !strcmp(type.dataTypeString, "byte"))
1257 value.c = *(char *)((byte *)object + offset);
1261 value.i = *(int *)((byte *)object + offset);
1264 if(!isFirst) f.Puts(",\n");
1265 for(c = 0; c<indent; c++) f.Puts(" ");
1268 f.Putc((char)toupper(member.name[0]));
1269 f.Puts(member.name+1);
1271 WriteValue(f, type, value, indent);
1282 for(c = 0; c<indent; c++) f.Puts(" "); f.Puts("}");