annotate Resources/CodeGeneration/template.in.h @ 507:ce49eae4c887 bgo-commands-codegen

Codegen + Warning fixes
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 01 Mar 2019 16:18:38 +0100
parents baa9e1e932db
children 7105a0bad250
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
1 /*
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
2 1 2 3 4 5 6 7
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
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
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
5 Generated on {{currentDatetime}} by stonegentool
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
6
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
7 */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
8 #pragma once
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
9
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
10 #include <exception>
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
11 #include <iostream>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
12 #include <string>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
13 #include <sstream>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
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>
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
16 #include <optional>
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
17 #include <json/json.h>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
18
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
19 //#define STONEGEN_NO_CPP11 1
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
20
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
21 #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
22 #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
23 #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
24 #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
25 #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
26
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
27 namespace {{rootName}}
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
28 {
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
29 /** Throws in case of problem */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
30 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
31 {
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 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
33 }
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
34
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
35 inline Json::Value _StoneSerializeValue(int32_t value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
36 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
37 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
38 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
39 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
40
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
41 /** Throws in case of problem */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
42 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
43 {
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
44 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
45 }
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
46
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
47 inline Json::Value _StoneSerializeValue(double value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
48 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
49 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
50 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
51 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
52
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
53 /** Throws in case of problem */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
54 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
55 {
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
56 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
57 }
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
58
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
59 inline Json::Value _StoneSerializeValue(bool value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
60 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
61 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
62 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
63 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
64
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
65 /** Throws in case of problem */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
66 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
67 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
68 , 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
69 {
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
70 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
71 }
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
72
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
73 inline Json::Value _StoneSerializeValue(const std::string& value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
74 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
75 // the following is better than
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
76 Json::Value result(value.data(),value.data()+value.size());
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
77 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
78 }
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
79
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
80 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
81 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
82 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
83 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
84 txt[i] = ' ';
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
85 txt[indent] = 0;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
86 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
87 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
88 return retVal;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
89 }
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 // generic dumper
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
92 template<typename T>
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
93 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
94 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
95 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
96 return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
97 }
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 // string dumper
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
100 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
101 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
102 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
103 return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
104 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
105
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
106 /** Throws in case of problem */
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
107 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
108 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
109 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
110 {
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
111 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
112 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
113 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
114 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
115 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
116 {
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 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
118 _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
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 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
121 _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
122
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 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
124 }
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
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 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
128 Json::Value _StoneSerializeValue(const std::map<std::string,T>& value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
129 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
130 Json::Value result(Json::objectValue);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
131
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 495
diff changeset
132 for (typename std::map<std::string, T>::const_iterator it = value.cbegin();
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
133 it != value.cend(); ++it)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
134 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
135 // 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
136 result[it->first] = _StoneSerializeValue(it->second);
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
137 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
138 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
139 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
140
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
141 template<typename T>
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
142 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
143 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
144 out << MakeIndent(indent) << "{\n";
499
baa9e1e932db wasm + ts demonstrator WORKS!
bgo-osimis
parents: 495
diff changeset
145 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
146 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
147 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
148 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
149 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
150 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
151 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
152 return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
153 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
154
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
155 /** Throws in case of problem */
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
156 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
157 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
158 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
159 {
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
160 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
161 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
162 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
163 {
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 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
165 _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
166 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
167 }
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
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 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
171 Json::Value _StoneSerializeValue(const std::vector<T>& value)
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
172 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
173 Json::Value result(Json::arrayValue);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
174 for (size_t i = 0; i < value.size(); ++i)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
175 {
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
176 result.append(_StoneSerializeValue(value[i]));
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
177 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
178 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
179 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
180
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
181 template<typename T>
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
182 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
183 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
184 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
185 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
186 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
187 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
188 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
189 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
190 return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
191 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
192
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
193 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
194 {
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
195 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
196 {
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
197 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
198 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
199 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
200 }
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
201 }
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
202
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
203 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
204 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
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 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
207
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 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
209 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
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 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
212 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
213 << "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
214 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
215 }
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
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 // 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
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 // 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
221 {% 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
222 enum {{enum['name']}} {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
223 {% 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
224 {%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
225
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
226 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
227 {{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
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 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
230 }
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
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
232 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
233 {
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 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
235 }
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
236
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
237 inline std::string ToString(const {{enum['name']}}& value)
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
238 {
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
239 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}})
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
240 {
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
241 return std::string("{{key}}");
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
242 }
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
243 {%endfor%};
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
244 }
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
245
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
246 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
247 {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
248 {% for key in enum['fields']%} if( strValue == std::string("{{key}}") )
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
249 {
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
250 value = {{enum['name']}}_{{key}};
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
251 }
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
252 {%endfor%}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
253 std::stringstream ss;
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
254 ss << "String \"" << strValue << "\" cannot be converted to {{enum['name']}}. Possible values are: {% for key in enum['fields']%}{{key}}{% endfor %}";
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
255 std::string msg = ss.str();
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
256 throw std::runtime_error(msg);
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
257 }
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
258
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
259 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0)
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
260 {
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
261 {% 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
262 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
263 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
264 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
265 {%endfor%} return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
266 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
267
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
268 {%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
269 {% 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
270 #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
271 #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
272 #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
273
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
274 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
275 {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
276 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} {{CanonToCpp(struct['fields'][key])}} {{key}};
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
277 {% endfor %}{% endif %}{% endif %}
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
278 {{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
279 {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
280 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} this->{{key}} = {{key}};
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
281 {% 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
282 };
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
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
284 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
285 {
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
286 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} _StoneDeserializeValue(destValue.{{key}}, value["{{key}}"]);
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
287 {% 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
288
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
289 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
290 {
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
291 Json::Value result(Json::objectValue);
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
292 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} result["{{key}}"] = _StoneSerializeValue(value.{{key}});
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
293 {% 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
294 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
295 }
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
296
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
297 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
298 {
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
299 out << MakeIndent(indent) << "{\n";
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
300 {% 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
301 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
302 out << "\n";
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
303 {% 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
304 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
305 return out;
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
306 }
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
307
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
308 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
309 {
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
310 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
311 _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
312 }
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
313
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
314 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
315 {
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
316 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
317 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
318 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
319 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
320 }
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
321
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
322 inline std::string StoneSerialize(const {{struct['name']}}& value)
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
323 {
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
324 Json::Value resultJson = StoneSerializeToJson(value);
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
325 std::string resultStr = resultJson.toStyledString();
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
326 return resultStr;
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
327 }
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
328
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 #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
330 #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
331 #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
332 {% 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
333 #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
334 #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
335 #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
336
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
337 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
338 {
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
339 public:
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
340 {% for struct in structs%} virtual bool Handle(const {{struct['name']}}& value) = 0;
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
341 {% endfor %} };
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
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 /** Service function for StoneDispatchToHandler */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
344 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
345 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
346 {
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 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
348 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
349 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
350 {
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
351 // 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
352 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
353 }
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
354 {% for struct in structs%} else if (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
355 {
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
356 {{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
357 _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
358 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
359 }
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 {% endfor %} 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
361 {
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 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
363 }
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
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
366 /** Takes a serialized type and passes this to the handler */
507
ce49eae4c887 Codegen + Warning fixes
Benjamin Golinvaux <bgo@osimis.io>
parents: 499
diff changeset
367 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
368 {
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 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
370
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 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
372 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
373
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
374 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
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 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
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 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
379 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
380 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
381 &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
382 &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
383 );
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 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
385 {
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 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
387 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
388 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
389 }
495
6405435480ae Fixed template to add dump capabilities + started work on an integrated TS/WASM test
bgo-osimis
parents: 494
diff changeset
390 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
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
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 #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
394 #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
395 #endif //_MSC_VER
490
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
396 }