Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/playground.ts @ 490:6470248790db bgo-commands-codegen
ongoing codegen work
author | bgo-osimis |
---|---|
date | Mon, 18 Feb 2019 15:38:05 +0100 |
parents | |
children | 8e7e151ef472 |
comparison
equal
deleted
inserted
replaced
489:f6b7f113cf27 | 490:6470248790db |
---|---|
1 /* | |
2 1 2 3 4 5 6 7 | |
3 12345678901234567890123456789012345678901234567890123456789012345678901234567890 | |
4 */ | |
5 | |
6 namespace VsolStuff | |
7 { | |
8 enum EnumMonth0 | |
9 { | |
10 January, | |
11 February, | |
12 March | |
13 }; | |
14 | |
15 // interface Serializer | |
16 // { | |
17 // Serialize(value: number): string; | |
18 // Serialize(value: string): string; | |
19 // Serialize(value: EnumMonth0): string; | |
20 // }; | |
21 function printf(value: any):void | |
22 { | |
23 console.log(value) | |
24 } | |
25 | |
26 // function StoneSerialize(value: string) : string; | |
27 // function StoneSerialize(value: number) : string; | |
28 // function StoneSerialize(value: EnumMonth0) : string; | |
29 function StoneSerialize<T>(value: T[]) : string; | |
30 | |
31 function StoneSerialize<T>(value: T[] | EnumMonth0) : string | |
32 { | |
33 let valueType = typeof value; | |
34 printf(`About to serialize value. Type is ${valueType}`) | |
35 printf(`About to serialize value. Type is ${typeof value}`) | |
36 return "Choucroute"; | |
37 | |
38 } | |
39 | |
40 function main():number | |
41 { | |
42 enum Color {Red = 1, Green = 2, Blue = 4} | |
43 let color: Color = Color.Green; | |
44 printf("---------------------------"); | |
45 printf(`typeof color: ${typeof color}`); | |
46 printf("---------------------------"); | |
47 let colors: Color[] = [] | |
48 colors.push(Color.Green); | |
49 colors.push(Color.Red); | |
50 printf(`typeof colors: ${typeof colors}`); | |
51 printf(`Array.isArray(colors): ${Array.isArray(colors)}`); | |
52 printf("---------------------------"); | |
53 | |
54 | |
55 let toto:EnumMonth0[] = []; | |
56 | |
57 toto.push(EnumMonth0.February); | |
58 toto.push(EnumMonth0.March); | |
59 | |
60 printf(JSON.stringify(toto)); | |
61 | |
62 return 0; | |
63 | |
64 } | |
65 | |
66 main() | |
67 | |
68 // string StoneSerialize_number(int32_t value) | |
69 // { | |
70 | |
71 // Json::Value result(value); | |
72 // return result; | |
73 // } | |
74 | |
75 // Json::Value StoneSerialize(double value) | |
76 // { | |
77 // Json::Value result(value); | |
78 // return result; | |
79 // } | |
80 | |
81 // Json::Value StoneSerialize(bool value) | |
82 // { | |
83 // Json::Value result(value); | |
84 // return result; | |
85 // } | |
86 | |
87 // Json::Value StoneSerialize(const std::string& value) | |
88 // { | |
89 // // the following is better than | |
90 // Json::Value result(value.data(),value.data()+value.size()); | |
91 // return result; | |
92 // } | |
93 | |
94 // template<typename T> | |
95 // Json::Value StoneSerialize(const std::map<std::string,T>& value) | |
96 // { | |
97 // Json::Value result(Json::objectValue); | |
98 | |
99 // for (std::map<std::string, T>::const_iterator it = value.cbegin(); | |
100 // it != value.cend(); ++it) | |
101 // { | |
102 // // it->first it->second | |
103 // result[it->first] = StoneSerialize(it->second); | |
104 // } | |
105 // return result; | |
106 // } | |
107 | |
108 // template<typename T> | |
109 // Json::Value StoneSerialize(const std::vector<T>& value) | |
110 // { | |
111 // Json::Value result(Json::arrayValue); | |
112 // for (size_t i = 0; i < value.size(); ++i) | |
113 // { | |
114 // result.append(StoneSerialize(value[i])); | |
115 // } | |
116 // return result; | |
117 // } | |
118 | |
119 // enum EnumMonth0 | |
120 // { | |
121 // January, | |
122 // February, | |
123 // March | |
124 // }; | |
125 | |
126 // std::string ToString(EnumMonth0 value) | |
127 // { | |
128 // switch(value) | |
129 // { | |
130 // case January: | |
131 // return "January"; | |
132 // case February: | |
133 // return "February"; | |
134 // case March: | |
135 // return "March"; | |
136 // default: | |
137 // { | |
138 // std::stringstream ss; | |
139 // ss << "Unrecognized EnumMonth0 value (" << static_cast<int64_t>(value) << ")"; | |
140 // throw std::runtime_error(ss.str()); | |
141 // } | |
142 // } | |
143 // } | |
144 | |
145 // void FromString(EnumMonth0& value, std::string strValue) | |
146 // { | |
147 // if (strValue == "January" || strValue == "EnumMonth0_January") | |
148 // { | |
149 // return January; | |
150 // } | |
151 // else if (strValue == "February" || strValue == "EnumMonth0_February") | |
152 // { | |
153 // return February; | |
154 // } | |
155 // #error Not implemented yet | |
156 // } | |
157 | |
158 // Json::Value StoneSerialize(const EnumMonth0& value) | |
159 // { | |
160 // return StoneSerialize(ToString(value)); | |
161 // } | |
162 // struct Message1 | |
163 // { | |
164 // int32_t a; | |
165 // std::string b; | |
166 // EnumMonth0 c; | |
167 // bool d; | |
168 // }; | |
169 | |
170 // struct Message2 | |
171 // { | |
172 // std::string toto; | |
173 // std::vector<Message1> tata; | |
174 // std::vector<std::string> tutu; | |
175 // std::map<std::string, std::string> titi; | |
176 // std::map<std::string, Message1> lulu; | |
177 // }; | |
178 | |
179 // Json::Value StoneSerialize(const Message1& value) | |
180 // { | |
181 // Json::Value result(Json::objectValue); | |
182 // result["a"] = StoneSerialize(value.a); | |
183 // result["b"] = StoneSerialize(value.b); | |
184 // result["c"] = StoneSerialize(value.c); | |
185 // result["d"] = StoneSerialize(value.d); | |
186 // return result; | |
187 // } | |
188 | |
189 // Json::Value StoneSerialize(const Message2& value) | |
190 // { | |
191 // Json::Value result(Json::objectValue); | |
192 // result["toto"] = StoneSerialize(value.toto); | |
193 // result["tata"] = StoneSerialize(value.tata); | |
194 // result["tutu"] = StoneSerialize(value.tutu); | |
195 // result["titi"] = StoneSerialize(value.titi); | |
196 // result["lulu"] = StoneSerialize(value.lulu); | |
197 // return result; | |
198 // } | |
199 // } | |
200 | |
201 // int main() | |
202 // { | |
203 // VsolStuff::Message1 msg1_0; | |
204 // msg1_0.a = 42; | |
205 // msg1_0.b = "Benjamin"; | |
206 // msg1_0.c = VsolStuff::January; | |
207 // msg1_0.d = true; | |
208 | |
209 // VsolStuff::Message1 msg1_1; | |
210 // msg1_1.a = 43; | |
211 // msg1_1.b = "Sandrine"; | |
212 // msg1_1.c = VsolStuff::March; | |
213 // msg1_0.d = false; | |
214 | |
215 // // std::string toto; | |
216 // // std::vector<Message1> tata; | |
217 // // std::vector<std::string> tutu; | |
218 // // std::map<int32_t, std::string> titi; | |
219 // // std::map<int32_t, Message1> lulu; | |
220 | |
221 // VsolStuff::Message2 msg2_0; | |
222 // msg2_0.toto = "Prout zizi"; | |
223 // msg2_0.tata.push_back(msg1_0); | |
224 // msg2_0.tata.push_back(msg1_1); | |
225 // msg2_0.tutu.push_back("Mercadet"); | |
226 // msg2_0.tutu.push_back("Poisson"); | |
227 // msg2_0.titi["44"] = "key 44"; | |
228 // msg2_0.titi["45"] = "key 45"; | |
229 // msg2_0.lulu["54"] = msg1_1; | |
230 // msg2_0.lulu["55"] = msg1_0; | |
231 // auto result = VsolStuff::StoneSerialize(msg2_0); | |
232 // auto resultStr = result.toStyledString(); | |
233 | |
234 // Json::Value readValue; | |
235 | |
236 // Json::CharReaderBuilder builder; | |
237 // Json::CharReader* reader = builder.newCharReader(); | |
238 // std::string errors; | |
239 | |
240 // bool ok = reader->parse( | |
241 // resultStr.c_str(), | |
242 // resultStr.c_str() + resultStr.size(), | |
243 // &readValue, | |
244 // &errors | |
245 // ); | |
246 // delete reader; | |
247 | |
248 // if (!ok) | |
249 // { | |
250 // std::stringstream ss; | |
251 // ss << "Json parsing error: " << errors; | |
252 // throw std::runtime_error(ss.str()); | |
253 // } | |
254 // std::cout << readValue.get("toto", "Default Value").asString() << std::endl; | |
255 // return 0; | |
256 // } | |
257 | |
258 | |
259 } | |
260 |