38 allow_missing_entries_ =
false;
49 SIZE_LIMIT_UNDEFINED = 0,
64 const std::size_t size = 0,
65 const std::size_t min = 0,
66 const std::size_t max = 0)
const
72 case SIZE_LIMIT_EQUAL:
73 ARILES2_ASSERT(size == min,
"Actual number of entries is not the same as expected.");
75 case SIZE_LIMIT_RANGE:
76 ARILES2_ASSERT(min <= size,
"Actual number of entries is lower than expected.");
77 ARILES2_ASSERT(max >= size,
"Actual number of entries is larger than expected.");
80 ARILES2_ASSERT(min <= size,
"Actual number of entries is lower than expected.");
83 ARILES2_THROW(
"Internal logic error.");
95 static void openFile(std::ifstream &config_ifs,
const std::string &file_name)
97 config_ifs.open(file_name.c_str());
98 if (!config_ifs.good())
100 std::string file_name_default = file_name;
101 config_ifs.open(file_name_default.c_str());
103 ARILES2_PERSISTENT_ASSERT(
104 true == config_ifs.good(),
105 std::string(
"Could not open configuration file: ") + file_name.c_str());
111 ARILES2_TRACE_FUNCTION;
112 ARILES2_TRACE_VALUE(name);
114 if (
false == name.empty())
116 return (startMapEntry(name));
123 ARILES2_TRACE_FUNCTION;
124 if (
false == name.empty())
131 virtual bool startRoot(
const std::vector<std::string> &subtree)
133 ARILES2_TRACE_FUNCTION;
136 if (0 == subtree.size())
138 result = this->startRoot(
"");
142 result = this->startRoot(subtree[0]);
143 for (std::size_t i = 1; i < subtree.size() and
true == result; ++i)
145 this->startMap(SIZE_LIMIT_MIN, 1);
146 result &= (this->startMapEntry(subtree[i]));
153 virtual void endRoot(
const std::vector<std::string> &subtree)
155 ARILES2_TRACE_FUNCTION;
156 for (std::size_t i = 1; i < subtree.size(); ++i)
161 if (0 == subtree.size())
180 for (std::size_t i = 0; i < subtree.size(); ++i)
186 result += subtree[i];
193 template <
class t_Entry>
197 parameters.allow_missing_entries_ ? SIZE_LIMIT_NONE : SIZE_LIMIT_MIN,
198 ariles2::apply<ariles2::Count>(entry));
203 const std::size_t = 0,
204 const std::size_t = 0)
217 ARILES2_TRACE_FUNCTION;
218 ARILES2_UNUSED_ARG(child_name)
225 virtual void endMapEntry() = 0;
234 const std::size_t = 0,
235 const std::size_t = 0)
241 ARILES2_THROW(
"startIteratedMapElement() is not supported.");
254 ARILES2_TRACE_FUNCTION;
258 this->startMap(SIZE_LIMIT_RANGE, 1, 2);
260 if (this->startMapEntry(
"is_null"))
262 this->readElement(is_null);
267 ARILES2_PERSISTENT_ASSERT(
268 true == param.allow_missing_entries_,
"Pointer entry does not include 'is_null' subentry.");
271 if (
false == is_null)
273 ARILES2_ASSERT(
true == this->startMapEntry(
"value"),
"Missing value in a pointer entry.");
280 if (
false == is_null)
288 virtual std::size_t startArray() = 0;
290 virtual void endArrayElement() = 0;
291 virtual void endArray() = 0;
295 return (startArray());
313 if (param.flat_matrices_)
315 if (
true == dynamic or
true == param.explicit_matrix_size_)
317 this->startMap(SIZE_LIMIT_EQUAL, 3);
319 ARILES2_ASSERT(
true == this->startMapEntry(
"cols"),
"Missing 'cols' in a matrix entry.");
320 this->readElement(cols);
323 ARILES2_ASSERT(
true == this->startMapEntry(
"rows"),
"Missing 'rows' in a matrix entry.");
324 this->readElement(rows);
327 ARILES2_ASSERT(
true == this->startMapEntry(
"data"),
"Missing 'data' in a matrix entry.");
329 const std::size_t vec_len = this->startVector();
330 ARILES2_ASSERT(cols * rows == vec_len,
"Inconsistent matrix size.");
339 rows = this->startArray();
342 cols = this->startVector();
348 if (not param.flat_matrices_ and 0 != row_index)
350 this->startArrayElement();
351 const std::size_t vec_len = this->startVector();
352 ARILES2_ASSERT(cols == vec_len,
"Inconsistent matrix row length.");
357 this->startVectorElement();
361 this->endVectorElement();
365 if (not param.flat_matrices_)
368 this->endArrayElement();
373 if (param.flat_matrices_)
390 template <
class t_Scalar>
393 ARILES2_PERSISTENT_ASSERT(2 == this->startArray(),
"Wrong number of elements in a complex number");
395 this->startArrayElement();
396 this->readElement(value);
398 this->endArrayElement();
399 this->startArrayElement();
400 this->readElement(value);
402 this->endArrayElement();
407 readElement<float>(entry);
411 readElement<double>(entry);
415 #define ARILES2_BASIC_TYPE(type) virtual void readElement(type &entry) = 0;
419 #undef ARILES2_BASIC_TYPE
422 template <
class t_Entry,
class t_Subtree>
425 ARILES2_TRACE_FUNCTION;
426 ARILES2_TRACE_TYPE(entry);
429 if (this->startRoot(subtree))
435 catch (
const std::exception &e)
438 std::string(
"Failed to parse entry <") + convertSubtreeToString(subtree) +
"> || "
442 this->endRoot(subtree);
446 ARILES2_PERSISTENT_ASSERT(
447 true == param.allow_missing_entries_,
448 std::string(
"Configuration file does not contain entry '") + convertSubtreeToString(subtree)
454 template <
class t_Entry>
457 const std::string &name,
459 const bool override_missing_entries_locally =
false)
461 ARILES2_TRACE_FUNCTION;
462 ARILES2_TRACE_VALUE(name);
463 ARILES2_TRACE_TYPE(entry);
465 if (this->startMapEntry(name))
471 catch (
const std::exception &e)
473 ARILES2_THROW(std::string(
"Failed to parse entry <") + name +
"> || " + e.what());
481 ARILES2_PERSISTENT_ASSERT(
482 false == override_missing_entries_locally and
true == param.allow_missing_entries_,
483 std::string(
"Configuration file does not contain entry '") + name +
"'.");
488 template <
typename t_Element>
491 ARILES2_TRACE_FUNCTION;
492 ARILES2_TRACE_TYPE(element);
494 this->startArrayElement();
496 this->endArrayElement();
499 template <
typename t_Element>
502 ARILES2_TRACE_FUNCTION;
503 ARILES2_TRACE_TYPE(element);
505 this->startVectorElement();
506 this->readElement(element);
507 this->endVectorElement();
510 template <
typename t_Element>
513 ARILES2_TRACE_FUNCTION;
515 this->startMatrixElement();
516 this->readElement(element);
517 this->endMatrixElement();
527 #define ARILES2_NAMED_ENTRY_read(v, entry, name) visitor.visitMapEntry(entry, #name, parameters);
528 #define ARILES2_PARENT_read(v, entry)
529 #define ARILES2_VISIT_read \
530 template <class t_Visitor> \
532 t_Visitor &visitor, \
533 const typename t_Visitor::Parameters ¶meters, \
534 ARILES2_IS_BASE_ENABLER(ariles2::read::Visitor, t_Visitor)) \
536 ARILES2_TRACE_FUNCTION; \
537 ARILES2_UNUSED_ARG(visitor); \
538 ARILES2_UNUSED_ARG(parameters); \
539 arilesVisitParents(visitor, parameters); \
540 ARILES2_ENTRIES(read) \
543 #define ARILES2_METHODS_read ARILES2_METHODS(read, ARILES2_EMPTY_MACRO, ARILES2_EMPTY_MACRO)
544 #define ARILES2_BASE_METHODS_read ARILES2_BASE_METHODS(read)