Mercurial > hg > orthanc-stone
annotate Resources/CodeGeneration/template.in.h.j2 @ 517:64ee3033e1ca bgo-commands-codegen
dummy dtor to check proper deletion
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 12 Mar 2019 08:51:35 +0100 |
parents | 1dbf2d9ed1e4 |
children | 17106b29ed6d |
rev | line source |
---|---|
490 | 1 /* |
2 1 2 3 4 5 6 7 | |
3 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
4 |
507 | 5 Generated on {{currentDatetime}} by stonegentool |
6 | |
490 | 7 */ |
507 | 8 #pragma once |
490 | 9 |
507 | 10 #include <exception> |
490 | 11 #include <iostream> |
12 #include <string> | |
13 #include <sstream> | |
14 #include <assert.h> | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
15 #include <memory> |
490 | 16 #include <json/json.h> |
17 | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
18 //#define STONEGEN_NO_CPP11 1 |
490 | 19 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
20 #ifdef STONEGEN_NO_CPP11 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
21 #define StoneSmartPtr std::auto_ptr |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
22 #else |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
23 #define StoneSmartPtr std::unique_ptr |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
24 #endif |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
25 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
26 namespace {{rootName}} |
490 | 27 { |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
28 /** Throws in case of problem */ |
507 | 29 inline void _StoneDeserializeValue(int32_t& destValue, const Json::Value& jsonValue) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
30 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
31 destValue = jsonValue.asInt(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
32 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
33 |
507 | 34 inline Json::Value _StoneSerializeValue(int32_t value) |
490 | 35 { |
36 Json::Value result(value); | |
37 return result; | |
38 } | |
39 | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
40 inline void _StoneDeserializeValue(Json::Value& destValue, const Json::Value& jsonValue) |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
41 { |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
42 destValue = jsonValue; |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
43 } |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
44 |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
45 inline Json::Value _StoneSerializeValue(Json::Value value) |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
46 { |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
47 return value; |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
48 } |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
49 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
50 /** Throws in case of problem */ |
507 | 51 inline void _StoneDeserializeValue(double& destValue, const Json::Value& jsonValue) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
52 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
53 destValue = jsonValue.asDouble(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
54 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
55 |
507 | 56 inline Json::Value _StoneSerializeValue(double value) |
490 | 57 { |
58 Json::Value result(value); | |
59 return result; | |
60 } | |
61 | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
62 /** Throws in case of problem */ |
507 | 63 inline void _StoneDeserializeValue(bool& destValue, const Json::Value& jsonValue) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
64 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
65 destValue = jsonValue.asBool(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
66 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
67 |
507 | 68 inline Json::Value _StoneSerializeValue(bool value) |
490 | 69 { |
70 Json::Value result(value); | |
71 return result; | |
72 } | |
73 | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
74 /** Throws in case of problem */ |
507 | 75 inline void _StoneDeserializeValue( |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
76 std::string& destValue |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
77 , const Json::Value& jsonValue) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
78 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
79 destValue = jsonValue.asString(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
80 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
81 |
507 | 82 inline Json::Value _StoneSerializeValue(const std::string& value) |
490 | 83 { |
84 // the following is better than | |
85 Json::Value result(value.data(),value.data()+value.size()); | |
86 return result; | |
87 } | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
88 |
507 | 89 inline std::string MakeIndent(int indent) |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
90 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
91 char* txt = reinterpret_cast<char*>(malloc(indent+1)); // NO EXCEPTION BELOW!!!!!!!!!!!! |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
92 for(size_t i = 0; i < indent; ++i) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
93 txt[i] = ' '; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
94 txt[indent] = 0; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
95 std::string retVal(txt); |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
96 free(txt); // NO EXCEPTION ABOVE !!!!!!!!!! |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
97 return retVal; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
98 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
99 |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
100 // generic dumper |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
101 template<typename T> |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
102 std::ostream& StoneDumpValue(std::ostream& out, const T& value, int indent) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
103 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
104 out << MakeIndent(indent) << value; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
105 return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
106 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
107 |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
108 // string dumper |
507 | 109 inline std::ostream& StoneDumpValue(std::ostream& out, const std::string& value, int indent) |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
110 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
111 out << MakeIndent(indent) << "\"" << value << "\""; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
112 return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
113 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
114 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
115 /** Throws in case of problem */ |
490 | 116 template<typename T> |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
117 void _StoneDeserializeValue( |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
118 std::map<std::string, T>& destValue, const Json::Value& jsonValue) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
119 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
120 destValue.clear(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
121 for ( |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
122 Json::Value::const_iterator itr = jsonValue.begin(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
123 itr != jsonValue.end(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
124 itr++) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
125 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
126 std::string key; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
127 _StoneDeserializeValue(key, itr.key()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
128 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
129 T innerDestValue; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
130 _StoneDeserializeValue(innerDestValue, *itr); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
131 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
132 destValue[key] = innerDestValue; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
133 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
134 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
135 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
136 template<typename T> |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
137 Json::Value _StoneSerializeValue(const std::map<std::string,T>& value) |
490 | 138 { |
139 Json::Value result(Json::objectValue); | |
140 | |
499 | 141 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); |
490 | 142 it != value.cend(); ++it) |
143 { | |
144 // it->first it->second | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
145 result[it->first] = _StoneSerializeValue(it->second); |
490 | 146 } |
147 return result; | |
148 } | |
149 | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
150 template<typename T> |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
151 std::ostream& StoneDumpValue(std::ostream& out, const std::map<std::string,T>& value, int indent) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
152 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
153 out << MakeIndent(indent) << "{\n"; |
499 | 154 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
155 it != value.cend(); ++it) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
156 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
157 out << MakeIndent(indent+2) << "\"" << it->first << "\" : "; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
158 StoneDumpValue(out, it->second, indent+2); |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
159 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
160 out << MakeIndent(indent) << "}\n"; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
161 return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
162 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
163 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
164 /** Throws in case of problem */ |
490 | 165 template<typename T> |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
166 void _StoneDeserializeValue( |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
167 std::vector<T>& destValue, const Json::Value& jsonValue) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
168 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
169 destValue.clear(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
170 destValue.reserve(jsonValue.size()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
171 for (Json::Value::ArrayIndex i = 0; i != jsonValue.size(); i++) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
172 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
173 T innerDestValue; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
174 _StoneDeserializeValue(innerDestValue, jsonValue[i]); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
175 destValue.push_back(innerDestValue); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
176 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
177 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
178 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
179 template<typename T> |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
180 Json::Value _StoneSerializeValue(const std::vector<T>& value) |
490 | 181 { |
182 Json::Value result(Json::arrayValue); | |
183 for (size_t i = 0; i < value.size(); ++i) | |
184 { | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
185 result.append(_StoneSerializeValue(value[i])); |
490 | 186 } |
187 return result; | |
188 } | |
189 | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
190 template<typename T> |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
191 std::ostream& StoneDumpValue(std::ostream& out, const std::vector<T>& value, int indent) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
192 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
193 out << MakeIndent(indent) << "[\n"; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
194 for (size_t i = 0; i < value.size(); ++i) |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
195 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
196 StoneDumpValue(out, value[i], indent+2); |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
197 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
198 out << MakeIndent(indent) << "]\n"; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
199 return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
200 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
201 |
507 | 202 inline void StoneCheckSerializedValueTypeGeneric(const Json::Value& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
203 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
204 if ((!value.isMember("type")) || (!value["type"].isString())) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
205 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
206 std::stringstream ss; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
207 ss << "Cannot deserialize value ('type' key invalid)"; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
208 throw std::runtime_error(ss.str()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
209 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
210 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
211 |
507 | 212 inline void StoneCheckSerializedValueType( |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
213 const Json::Value& value, std::string typeStr) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
214 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
215 StoneCheckSerializedValueTypeGeneric(value); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
216 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
217 std::string actTypeStr = value["type"].asString(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
218 if (actTypeStr != typeStr) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
219 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
220 std::stringstream ss; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
221 ss << "Cannot deserialize type" << actTypeStr |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
222 << "into " << typeStr; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
223 throw std::runtime_error(ss.str()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
224 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
225 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
226 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
227 // end of generic methods |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
228 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
229 // end of generic methods |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
230 {% for enum in enums%} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
231 enum {{enum['name']}} { |
507 | 232 {% for key in enum['fields']%} {{enum['name']}}_{{key}}, |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
233 {%endfor%} }; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
234 |
507 | 235 inline void _StoneDeserializeValue( |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
236 {{enum['name']}}& destValue, const Json::Value& jsonValue) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
237 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
238 destValue = static_cast<{{enum['name']}}>(jsonValue.asInt64()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
239 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
240 |
507 | 241 inline Json::Value _StoneSerializeValue(const {{enum['name']}}& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
242 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
243 return Json::Value(static_cast<int64_t>(value)); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
244 } |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
245 |
507 | 246 inline std::string ToString(const {{enum['name']}}& value) |
247 { | |
248 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) | |
249 { | |
250 return std::string("{{key}}"); | |
251 } | |
508
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
252 {%endfor%} std::stringstream ss; |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
253 ss << "Value \"" << value << "\" cannot be converted to {{enum['name']}}. Possible values are: " |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
254 {% for key in enum['fields']%} << " {{key}} = " << static_cast<int64_t>({{enum['name']}}_{{key}}) << ", " |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
255 {% endfor %} << std::endl; |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
256 std::string msg = ss.str(); |
7105a0bad250
- Added HandleSerializedMessage to IStoneApplication (empty impl)
Benjamin Golinvaux <bgo@osimis.io>
parents:
507
diff
changeset
|
257 throw std::runtime_error(msg); |
507 | 258 } |
259 | |
260 inline void FromString({{enum['name']}}& value, std::string strValue) | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
261 { |
507 | 262 {% for key in enum['fields']%} if( strValue == std::string("{{key}}") ) |
263 { | |
264 value = {{enum['name']}}_{{key}}; | |
265 } | |
266 {%endfor%} | |
267 std::stringstream ss; | |
268 ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}}{% endfor %}"; | |
269 std::string msg = ss.str(); | |
270 throw std::runtime_error(msg); | |
271 } | |
272 | |
273 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0) | |
274 { | |
275 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) | |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
276 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
277 out << MakeIndent(indent) << "{{key}}" << std::endl; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
278 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
279 {%endfor%} return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
280 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
281 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
282 {%endfor%} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
283 {% for struct in structs%} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
284 #ifdef _MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
285 #pragma region {{struct['name']}} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
286 #endif //_MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
287 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
288 struct {{struct['name']}} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
289 { |
507 | 290 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} {{CanonToCpp(struct['fields'][key])}} {{key}}; |
291 {% endfor %}{% endif %}{% endif %} | |
292 {{struct['name']}}({% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%}{{CanonToCpp(struct['fields'][key])}} {{key}} = {{CanonToCpp(struct['fields'][key])}}(){{ ", " if not loop.last }}{% endfor %}{% endif %}{% endif %}) | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
293 { |
507 | 294 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} this->{{key}} = {{key}}; |
295 {% endfor %}{% endif %}{% endif %} } | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
296 }; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
297 |
507 | 298 inline void _StoneDeserializeValue({{struct['name']}}& destValue, const Json::Value& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
299 { |
507 | 300 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} _StoneDeserializeValue(destValue.{{key}}, value["{{key}}"]); |
301 {% endfor %}{% endif %}{% endif %} } | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
302 |
507 | 303 inline Json::Value _StoneSerializeValue(const {{struct['name']}}& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
304 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
305 Json::Value result(Json::objectValue); |
507 | 306 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} result["{{key}}"] = _StoneSerializeValue(value.{{key}}); |
307 {% endfor %}{% endif %}{% endif %} | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
308 return result; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
309 } |
490 | 310 |
507 | 311 inline std::ostream& StoneDumpValue(std::ostream& out, const {{struct['name']}}& value, int indent = 0) |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
312 { |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
313 out << MakeIndent(indent) << "{\n"; |
507 | 314 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} out << MakeIndent(indent) << "{{key}}:\n"; |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
315 StoneDumpValue(out, value.{{key}},indent+2); |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
316 out << "\n"; |
507 | 317 {% endfor %}{% endif %}{% endif %} |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
318 out << MakeIndent(indent) << "}\n"; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
319 return out; |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
320 } |
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
321 |
507 | 322 inline void StoneDeserialize({{struct['name']}}& destValue, const Json::Value& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
323 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
324 StoneCheckSerializedValueType(value, "{{rootName}}.{{struct['name']}}"); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
325 _StoneDeserializeValue(destValue, value["value"]); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
326 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
327 |
507 | 328 inline Json::Value StoneSerializeToJson(const {{struct['name']}}& value) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
329 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
330 Json::Value result(Json::objectValue); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
331 result["type"] = "{{rootName}}.{{struct['name']}}"; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
332 result["value"] = _StoneSerializeValue(value); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
333 return result; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
334 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
335 |
507 | 336 inline std::string StoneSerialize(const {{struct['name']}}& value) |
337 { | |
338 Json::Value resultJson = StoneSerializeToJson(value); | |
339 std::string resultStr = resultJson.toStyledString(); | |
340 return resultStr; | |
341 } | |
342 | |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
343 #ifdef _MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
344 #pragma endregion {{struct['name']}} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
345 #endif //_MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
346 {% endfor %} |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
347 #ifdef _MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
348 #pragma region Dispatching code |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
349 #endif //_MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
350 |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
351 class IHandler |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
352 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
353 public: |
513
dea3787a8f4b
Added support for struct metadata, to disable/enable handler support in Typescript or C++
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
354 {% for struct in structs%}{% if struct['__meta__'].handleInCpp %} virtual bool Handle(const {{struct['name']}}& value) = 0; |
dea3787a8f4b
Added support for struct metadata, to disable/enable handler support in Typescript or C++
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
355 {% endif %}{% endfor %} }; |
490 | 356 |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
357 /** Service function for StoneDispatchToHandler */ |
507 | 358 inline bool StoneDispatchJsonToHandler( |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
359 const Json::Value& jsonValue, IHandler* handler) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
360 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
361 StoneCheckSerializedValueTypeGeneric(jsonValue); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
362 std::string type = jsonValue["type"].asString(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
363 if (type == "") |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
364 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
365 // this should never ever happen |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
366 throw std::runtime_error("Caught empty type while dispatching"); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
367 } |
513
dea3787a8f4b
Added support for struct metadata, to disable/enable handler support in Typescript or C++
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
368 {% for struct in structs%}{% if struct['__meta__'].handleInCpp %} else if (type == "{{rootName}}.{{struct['name']}}") |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
369 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
370 {{struct['name']}} value; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
371 _StoneDeserializeValue(value, jsonValue["value"]); |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
372 return handler->Handle(value); |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
373 } |
513
dea3787a8f4b
Added support for struct metadata, to disable/enable handler support in Typescript or C++
Benjamin Golinvaux <bgo@osimis.io>
parents:
508
diff
changeset
|
374 {% endif %}{% endfor %} else |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
375 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
376 return false; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
377 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
378 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
379 |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
380 /** Takes a serialized type and passes this to the handler */ |
507 | 381 inline bool StoneDispatchToHandler(std::string strValue, IHandler* handler) |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
382 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
383 Json::Value readValue; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
384 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
385 Json::CharReaderBuilder builder; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
386 Json::CharReader* reader = builder.newCharReader(); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
387 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
388 StoneSmartPtr<Json::CharReader> ptr(reader); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
389 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
390 std::string errors; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
391 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
392 bool ok = reader->parse( |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
393 strValue.c_str(), |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
394 strValue.c_str() + strValue.size(), |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
395 &readValue, |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
396 &errors |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
397 ); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
398 if (!ok) |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
399 { |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
400 std::stringstream ss; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
401 ss << "Jsoncpp parsing error: " << errors; |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
402 throw std::runtime_error(ss.str()); |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
403 } |
495
6405435480ae
Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents:
494
diff
changeset
|
404 return StoneDispatchJsonToHandler(readValue, handler); |
494
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
405 } |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
406 |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
407 #ifdef _MSC_VER |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
408 #pragma endregion Dispatching code |
fc17251477d6
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
bgo-osimis
parents:
490
diff
changeset
|
409 #endif //_MSC_VER |
490 | 410 } |