annotate Resources/CodeGeneration/template.in.h @ 493:6fbf2eae7c88 bgo-commands-codegen

All unit tests pass for generation, including handler and dispatcher
author bgo-osimis
date Fri, 22 Feb 2019 10:48:43 +0100
parents 6470248790db
children fc17251477d6
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
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
4 */
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
5
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
6 #include <iostream>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
7 #include <string>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
8 #include <sstream>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
9 #include <assert.h>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
10 #include <json/json.h>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
11
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
12
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
13 namespace VsolStuff
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
14 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
15 Json::Value StoneSerialize(int32_t value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
16 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
17 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
18 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
19 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
20
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
21 Json::Value StoneSerialize(double value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
22 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
23 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
24 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
25 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
26
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
27 Json::Value StoneSerialize(bool value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
28 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
29 Json::Value result(value);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
30 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
31 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
32
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
33 Json::Value StoneSerialize(const std::string& value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
34 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
35 // the following is better than
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
36 Json::Value result(value.data(),value.data()+value.size());
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
37 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
38 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
39
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
40 template<typename T>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
41 Json::Value StoneSerialize(const std::map<std::string,T>& value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
42 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
43 Json::Value result(Json::objectValue);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
44
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
45 for (std::map<std::string, T>::const_iterator it = value.cbegin();
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
46 it != value.cend(); ++it)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
47 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
48 // it->first it->second
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
49 result[it->first] = StoneSerialize(it->second);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
50 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
51 return result;
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
52 }
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
53
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
54 template<typename T>
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
55 Json::Value StoneSerialize(const std::vector<T>& value)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
56 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
57 Json::Value result(Json::arrayValue);
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
58 for (size_t i = 0; i < value.size(); ++i)
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
59 {
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
60 result.append(StoneSerialize(value[i]));
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
61 }
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
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
65 %enumerationscpp%
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
66
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
67 %structscpp%
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
68
6470248790db ongoing codegen work
bgo-osimis
parents:
diff changeset
69 }