MCPcopy Create free account
hub / github.com/R2Northstar/NorthstarLauncher / DecodeJsonTable

Function DecodeJsonTable

primedev/scripts/scriptjson.cpp:52–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51template <ScriptContext context>
52void DecodeJsonTable(HSQUIRRELVM sqvm, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj)
53{
54 g_pSquirrel[context]->newtable(sqvm);
55
56 for (auto itr = obj->MemberBegin(); itr != obj->MemberEnd(); itr++)
57 {
58 switch (itr->value.GetType())
59 {
60 case rapidjson::kObjectType:
61 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
62 DecodeJsonTable<context>(
63 sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&itr->value);
64 g_pSquirrel[context]->newslot(sqvm, -3, false);
65 break;
66 case rapidjson::kArrayType:
67 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
68 DecodeJsonArray<context>(
69 sqvm, (rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>*)&itr->value);
70 g_pSquirrel[context]->newslot(sqvm, -3, false);
71 break;
72 case rapidjson::kStringType:
73 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
74 g_pSquirrel[context]->pushstring(sqvm, itr->value.GetString(), -1);
75
76 g_pSquirrel[context]->newslot(sqvm, -3, false);
77 break;
78 case rapidjson::kTrueType:
79 case rapidjson::kFalseType:
80 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
81 g_pSquirrel[context]->pushbool(sqvm, itr->value.GetBool());
82 g_pSquirrel[context]->newslot(sqvm, -3, false);
83 break;
84 case rapidjson::kNumberType:
85 if (itr->value.IsDouble() || itr->value.IsFloat())
86 {
87 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
88 g_pSquirrel[context]->pushfloat(sqvm, itr->value.GetFloat());
89 }
90 else
91 {
92 g_pSquirrel[context]->pushstring(sqvm, itr->name.GetString(), -1);
93 g_pSquirrel[context]->pushinteger(sqvm, itr->value.GetInt());
94 }
95 g_pSquirrel[context]->newslot(sqvm, -3, false);
96 break;
97 case rapidjson::kNullType:
98 break;
99 }
100 }
101}
102
103template <ScriptContext context> void EncodeJSONTable(
104 SQTable* table,

Callers

nothing calls this directly

Calls 10

newtableMethod · 0.80
pushstringMethod · 0.80
newslotMethod · 0.80
pushboolMethod · 0.80
GetBoolMethod · 0.80
pushfloatMethod · 0.80
pushintegerMethod · 0.80
GetStringMethod · 0.45
GetFloatMethod · 0.45
GetIntMethod · 0.45

Tested by

no test coverage detected