comparison Resources/CodeGeneration/template.in.h.j2 @ 682:e8b83fe55a33 am-dev

added support for float + map<TK, TV> instead of only map<string, T>
author Alain Mazy <alain@mazy.be>
date Thu, 16 May 2019 15:04:41 +0200
parents 1b47f17863ba
children 342f3e04bfa9
comparison
equal deleted inserted replaced
677:077f28e3ea3d 682:e8b83fe55a33
107 Json::Value result(value); 107 Json::Value result(value);
108 return result; 108 return result;
109 } 109 }
110 110
111 /** Throws in case of problem */ 111 /** Throws in case of problem */
112 inline void _StoneDeserializeValue(float& destValue, const Json::Value& jsonValue)
113 {
114 if (!jsonValue.isNull())
115 {
116 destValue = jsonValue.asFloat();
117 }
118 }
119
120 inline Json::Value _StoneSerializeValue(float value)
121 {
122 Json::Value result(value);
123 return result;
124 }
125
126 /** Throws in case of problem */
112 inline void _StoneDeserializeValue(bool& destValue, const Json::Value& jsonValue) 127 inline void _StoneDeserializeValue(bool& destValue, const Json::Value& jsonValue)
113 { 128 {
114 if (!jsonValue.isNull()) 129 if (!jsonValue.isNull())
115 { 130 {
116 destValue = jsonValue.asBool(); 131 destValue = jsonValue.asBool();
166 out << MakeIndent(indent) << "\"" << value << "\""; 181 out << MakeIndent(indent) << "\"" << value << "\"";
167 return out; 182 return out;
168 } 183 }
169 184
170 /** Throws in case of problem */ 185 /** Throws in case of problem */
171 template<typename T> 186 template<typename TK, typename TV>
172 void _StoneDeserializeValue( 187 void _StoneDeserializeValue(
173 std::map<std::string, T>& destValue, const Json::Value& jsonValue) 188 std::map<TK, TV>& destValue, const Json::Value& jsonValue)
174 { 189 {
175 if (!jsonValue.isNull()) 190 if (!jsonValue.isNull())
176 { 191 {
177 destValue.clear(); 192 destValue.clear();
178 for ( 193 for (
179 Json::Value::const_iterator itr = jsonValue.begin(); 194 Json::Value::const_iterator itr = jsonValue.begin();
180 itr != jsonValue.end(); 195 itr != jsonValue.end();
181 itr++) 196 itr++)
182 { 197 {
183 std::string key; 198 TK key;
184 _StoneDeserializeValue(key, itr.key()); 199 _StoneDeserializeValue(key, itr.key());
185 200
186 T innerDestValue; 201 TV innerDestValue;
187 _StoneDeserializeValue(innerDestValue, *itr); 202 _StoneDeserializeValue(innerDestValue, *itr);
188 203
189 destValue[key] = innerDestValue; 204 destValue[key] = innerDestValue;
190 } 205 }
191 } 206 }
192 } 207 }
193 208 template<typename TK, typename TV>
194 template<typename T> 209 Json::Value _StoneSerializeValue(const std::map<TK, TV>& value)
195 Json::Value _StoneSerializeValue(const std::map<std::string,T>& value)
196 { 210 {
197 Json::Value result(Json::objectValue); 211 Json::Value result(Json::objectValue);
198 212
199 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); 213 for (typename std::map<TK, TV>::const_iterator it = value.cbegin();
200 it != value.cend(); ++it) 214 it != value.cend(); ++it)
201 { 215 {
202 // it->first it->second 216 // it->first it->second
203 result[it->first] = _StoneSerializeValue(it->second); 217 result[it->first] = _StoneSerializeValue(it->second);
204 } 218 }
205 return result; 219 return result;
206 } 220 }
207 221
208 template<typename T> 222 template<typename TK, typename TV>
209 std::ostream& StoneDumpValue(std::ostream& out, const std::map<std::string,T>& value, size_t indent) 223 std::ostream& StoneDumpValue(std::ostream& out, const std::map<TK, TV>& value, size_t indent)
210 { 224 {
211 out << MakeIndent(indent) << "{\n"; 225 out << MakeIndent(indent) << "{\n";
212 for (typename std::map<std::string, T>::const_iterator it = value.cbegin(); 226 for (typename std::map<TK, TV>::const_iterator it = value.cbegin();
213 it != value.cend(); ++it) 227 it != value.cend(); ++it)
214 { 228 {
215 out << MakeIndent(indent+2) << "\"" << it->first << "\" : "; 229 out << MakeIndent(indent+2) << "\"" << it->first << "\" : ";
216 StoneDumpValue(out, it->second, indent+2); 230 StoneDumpValue(out, it->second, indent+2);
217 } 231 }