Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/template.in.h.j2 @ 524:9e241cef32a4 dev
fix warning
author | amazy |
---|---|
date | Tue, 12 Mar 2019 18:28:25 +0100 |
parents | 17106b29ed6d |
children | 75664eeacae5 |
comparison
equal
deleted
inserted
replaced
523:aa00a49444c6 | 524:9e241cef32a4 |
---|---|
84 // the following is better than | 84 // the following is better than |
85 Json::Value result(value.data(),value.data()+value.size()); | 85 Json::Value result(value.data(),value.data()+value.size()); |
86 return result; | 86 return result; |
87 } | 87 } |
88 | 88 |
89 inline std::string MakeIndent(int indent) | 89 inline std::string MakeIndent(size_t indent) |
90 { | 90 { |
91 char* txt = reinterpret_cast<char*>(malloc(indent+1)); // NO EXCEPTION BELOW!!!!!!!!!!!! | 91 char* txt = reinterpret_cast<char*>(malloc(indent+1)); // NO EXCEPTION BELOW!!!!!!!!!!!! |
92 for(size_t i = 0; i < indent; ++i) | 92 for(size_t i = 0; i < indent; ++i) |
93 txt[i] = ' '; | 93 txt[i] = ' '; |
94 txt[indent] = 0; | 94 txt[indent] = 0; |
97 return retVal; | 97 return retVal; |
98 } | 98 } |
99 | 99 |
100 // generic dumper | 100 // generic dumper |
101 template<typename T> | 101 template<typename T> |
102 std::ostream& StoneDumpValue(std::ostream& out, const T& value, int indent) | 102 std::ostream& StoneDumpValue(std::ostream& out, const T& value, size_t indent) |
103 { | 103 { |
104 out << MakeIndent(indent) << value; | 104 out << MakeIndent(indent) << value; |
105 return out; | 105 return out; |
106 } | 106 } |
107 | 107 |
108 // string dumper | 108 // string dumper |
109 inline std::ostream& StoneDumpValue(std::ostream& out, const std::string& value, int indent) | 109 inline std::ostream& StoneDumpValue(std::ostream& out, const std::string& value, size_t indent) |
110 { | 110 { |
111 out << MakeIndent(indent) << "\"" << value << "\""; | 111 out << MakeIndent(indent) << "\"" << value << "\""; |
112 return out; | 112 return out; |
113 } | 113 } |
114 | 114 |
146 } | 146 } |
147 return result; | 147 return result; |
148 } | 148 } |
149 | 149 |
150 template<typename T> | 150 template<typename T> |
151 std::ostream& StoneDumpValue(std::ostream& out, const std::map<std::string,T>& value, int indent) | 151 std::ostream& StoneDumpValue(std::ostream& out, const std::map<std::string,T>& value, size_t indent) |
152 { | 152 { |
153 out << MakeIndent(indent) << "{\n"; | 153 out << MakeIndent(indent) << "{\n"; |
154 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); | 154 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); |
155 it != value.cend(); ++it) | 155 it != value.cend(); ++it) |
156 { | 156 { |
186 } | 186 } |
187 return result; | 187 return result; |
188 } | 188 } |
189 | 189 |
190 template<typename T> | 190 template<typename T> |
191 std::ostream& StoneDumpValue(std::ostream& out, const std::vector<T>& value, int indent) | 191 std::ostream& StoneDumpValue(std::ostream& out, const std::vector<T>& value, size_t indent) |
192 { | 192 { |
193 out << MakeIndent(indent) << "[\n"; | 193 out << MakeIndent(indent) << "[\n"; |
194 for (size_t i = 0; i < value.size(); ++i) | 194 for (size_t i = 0; i < value.size(); ++i) |
195 { | 195 { |
196 StoneDumpValue(out, value[i], indent+2); | 196 StoneDumpValue(out, value[i], indent+2); |
271 { | 271 { |
272 std::string strValue = ToString(value); | 272 std::string strValue = ToString(value); |
273 return Json::Value(strValue); | 273 return Json::Value(strValue); |
274 } | 274 } |
275 | 275 |
276 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, int indent = 0) | 276 inline std::ostream& StoneDumpValue(std::ostream& out, const {{enum['name']}}& value, size_t indent = 0) |
277 { | 277 { |
278 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) | 278 {% for key in enum['fields']%} if( value == {{enum['name']}}_{{key}}) |
279 { | 279 { |
280 out << MakeIndent(indent) << "{{key}}" << std::endl; | 280 out << MakeIndent(indent) << "{{key}}" << std::endl; |
281 } | 281 } |
309 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} result["{{key}}"] = _StoneSerializeValue(value.{{key}}); | 309 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} result["{{key}}"] = _StoneSerializeValue(value.{{key}}); |
310 {% endfor %}{% endif %}{% endif %} | 310 {% endfor %}{% endif %}{% endif %} |
311 return result; | 311 return result; |
312 } | 312 } |
313 | 313 |
314 inline std::ostream& StoneDumpValue(std::ostream& out, const {{struct['name']}}& value, int indent = 0) | 314 inline std::ostream& StoneDumpValue(std::ostream& out, const {{struct['name']}}& value, size_t indent = 0) |
315 { | 315 { |
316 out << MakeIndent(indent) << "{\n"; | 316 out << MakeIndent(indent) << "{\n"; |
317 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} out << MakeIndent(indent) << "{{key}}:\n"; | 317 {% if struct %}{% if struct['fields'] %}{% for key in struct['fields']%} out << MakeIndent(indent) << "{{key}}:\n"; |
318 StoneDumpValue(out, value.{{key}},indent+2); | 318 StoneDumpValue(out, value.{{key}},indent+2); |
319 out << "\n"; | 319 out << "\n"; |