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