37 compact_arrays_ =
false;
43 template <
class t_Derived,
class t_Parameters>
58 static void openFile(std::ofstream &config_ofs,
const std::string &file_name)
60 config_ofs.open(file_name.c_str());
62 ARILES2_PERSISTENT_ASSERT(
63 true == config_ofs.good(),
64 std::string(
"Could not open configuration file for writing: ") + file_name.c_str());
71 ARILES2_TRACE_FUNCTION;
72 if (
false == name.empty())
77 virtual void endRoot(
const std::string &name)
79 ARILES2_TRACE_FUNCTION;
80 if (
false == name.empty())
88 virtual void flush() = 0;
107 ARILES2_UNUSED_ARG(map_name)
122 startMap(param, num_entries);
127 startMapEntry(map_name);
139 virtual void startArray(
const std::size_t size,
const bool compact =
false) = 0;
142 ARILES2_TRACE_FUNCTION;
146 ARILES2_TRACE_FUNCTION;
150 ARILES2_TRACE_FUNCTION;
156 ARILES2_TRACE_FUNCTION;
157 this->startArray(size,
true);
161 ARILES2_TRACE_FUNCTION;
162 this->startArrayElement();
166 ARILES2_TRACE_FUNCTION;
167 this->endArrayElement();
171 ARILES2_TRACE_FUNCTION;
178 const std::size_t cols,
179 const std::size_t rows,
182 ARILES2_TRACE_FUNCTION;
183 if (param.flat_matrices_)
185 if (dynamic or param.explicit_matrix_size_)
187 this->startMap(param, 3);
189 this->startMapEntry(
"cols");
190 this->writeElement(cols, param);
193 this->startMapEntry(
"rows");
194 this->writeElement(rows, param);
197 this->startMapEntry(
"data");
200 this->startVector(cols * rows);
204 this->startArray(rows,
true);
209 ARILES2_TRACE_FUNCTION;
210 if (not param.flat_matrices_)
212 this->startArrayElement();
213 this->startVector(cols);
218 ARILES2_TRACE_FUNCTION;
219 this->startVectorElement();
223 ARILES2_TRACE_FUNCTION;
224 this->endVectorElement();
228 ARILES2_TRACE_FUNCTION;
229 if (not param.flat_matrices_)
232 this->endArrayElement();
237 ARILES2_TRACE_FUNCTION;
238 if (param.flat_matrices_)
242 if (dynamic or param.explicit_matrix_size_)
260 this->startMap(param, 1);
261 this->startMapEntry(
"is_null");
262 this->writeElement(is_null, param);
267 this->startMap(param, 2);
268 this->startMapEntry(
"is_null");
269 this->writeElement(is_null, param);
271 this->startMapEntry(
"value");
276 if (
false == is_null)
284 template <
class t_Scalar>
287 this->startArray(2,
true);
288 this->startArrayElement();
289 this->writeElement(entry.real(), param);
290 this->endArrayElement();
291 this->startArrayElement();
292 this->writeElement(entry.imag(), param);
293 this->endArrayElement();
298 writeElement<float>(entry, param);
302 writeElement<double>(entry, param);
306 #define ARILES2_BASIC_TYPE(type) virtual void writeElement(const type &entry, const t_Parameters ¶m) = 0;
310 #undef ARILES2_BASIC_TYPE
312 template <
typename t_Entry>
315 ARILES2_TRACE_FUNCTION;
316 this->startRoot(entry_name, param);
317 apply_write(
static_cast<t_Derived &
>(*
this), entry, param);
318 this->endRoot(entry_name);
322 template <
typename t_Entry>
325 ARILES2_TRACE_FUNCTION;
326 ARILES2_TRACE_VALUE(entry_name);
327 ARILES2_TRACE_TYPE(entry);
329 this->startMapEntry(entry_name);
330 apply_write(
static_cast<t_Derived &
>(*
this), entry, param);
334 template <
typename t_Element>
337 ARILES2_TRACE_FUNCTION;
338 ARILES2_TRACE_TYPE(element);
340 this->startArrayElement();
341 apply_write(
static_cast<t_Derived &
>(*
this), element, param);
342 this->endArrayElement();
345 template <
typename t_Element>
348 ARILES2_TRACE_FUNCTION;
350 this->startVectorElement();
351 this->writeElement(element, param);
352 this->endVectorElement();
355 template <
typename t_Element>
358 ARILES2_TRACE_FUNCTION;
360 this->startMatrixElement();
361 this->writeElement(element, param);
362 this->endMatrixElement();
378 template <
class t_Entry>
381 startMap(parameters, ariles2::apply<ariles2::Count>(entry));
393 #define ARILES2_NAMED_ENTRY_write(v, entry, name) visitor.visitMapEntry(entry, #name, parameters);
394 #define ARILES2_PARENT_write(v, entry)
395 #define ARILES2_VISIT_write \
396 template <class t_Visitor> \
398 t_Visitor &visitor, \
399 const typename t_Visitor::Parameters ¶meters, \
400 ARILES2_IS_BASE_ENABLER(ariles2::write::Visitor, t_Visitor)) const \
402 ARILES2_TRACE_FUNCTION; \
403 ARILES2_UNUSED_ARG(visitor); \
404 ARILES2_UNUSED_ARG(parameters); \
405 arilesVisitParents(visitor, parameters); \
406 ARILES2_ENTRIES(write) \
409 #define ARILES2_METHODS_write ARILES2_METHODS(write, ARILES2_EMPTY_MACRO, const)
410 #define ARILES2_BASE_METHODS_write ARILES2_BASE_METHODS(write)