17#define CPPTOML_NO_RTTI
18#define CPPTOML_NO_EXCEPTIONS
26template <VariableType e>
96 const std::vector<MInt>&
asInt()
const {
104 TERMM(1,
"bad type");
108 const std::vector<MBool>&
asBool()
const {
110 TERMM(1,
"bad type");
137 TERMM(1,
"bad value type: " + std::to_string(
type()));
143 if(value->as<std::string>()) {
145 }
else if(value->as<int64_t>()) {
147 }
else if(value->as<
double>()) {
149 }
else if(value->as<
bool>()) {
152 TERMM(1,
"bad value type");
159 if(item->is_value()) {
162 std::vector<MString> data(1);
163 data[0] = item->as<std::string>()->get();
167 std::vector<MInt> data(1);
168#if defined(MAIA_GCC_COMPILER)
169#pragma GCC diagnostic push
170#pragma GCC diagnostic ignored "-Wnull-dereference"
172 data[0] =
static_cast<MInt>(item->as<int64_t>()->get());
173#if defined(MAIA_GCC_COMPILER)
174#pragma GCC diagnostic pop
179 std::vector<MFloat> data(1);
180 data[0] = item->as<
double>()->get();
184 std::vector<MBool> data(1);
185 data[0] = item->as<
bool>()->get();
189 TERMM(1,
"bad value type");
191 }
else if(item->is_array() || item->is_table()) {
192 if(item->as_array()->get().empty()) {
193 TERMM(1,
"array of size 0 found, cannot detect type");
198 auto v = *item->as_array()->get_array_of<std::string>();
199 std::vector<MString> data(v.size());
200 copy(v.begin(), v.end(), data.begin());
204 auto v = *item->as_array()->get_array_of<
MLong>();
205 std::vector<MInt> data(v.size());
206 copy(v.begin(), v.end(), data.begin());
210 auto v = *item->as_array()->get_array_of<
double>();
211 std::vector<MFloat> data(v.size());
212 copy(v.begin(), v.end(), data.begin());
216 auto v = *item->as_array()->get_array_of<
bool>();
217 std::vector<MBool> data(v.size());
218 copy(v.begin(), v.end(), data.begin());
222 TERMM(1,
"bad value type");
225 TERMM(1,
"item is not a value or array");
231 std::map<std::string, int>& solverAliases) {
233 for(
auto&& item : *tab) {
234 auto&& key = item.first;
235 if(key ==
"solverAlias") {
236 auto&& solverAliasesTable = item.second;
238 if(solverAliasesTable->is_table()) {
239 for(
auto&& alias : *solverAliasesTable->as_table()) {
243 solverAliases[alias.second->as<std::string>()->get()] = std::stoi(alias.first);
245 TERMM(1,
"solverAlias need to be defined as string!");
249 TERMM(1,
"solverAlias needs to be in table format: solverAlias.solverId = 'alias'!");
257 std::vector<std::string>& names,
258 std::vector<Property>& properties,
259 std::map<std::string, int>& solverAliases) {
269 for(
auto&& item : *tab) {
271 auto&& key = item.first;
272 auto&& value = item.second;
273 std::stringstream key_ss;
276 if(key_ss.str() ==
"default") {
281 k << names[0] <<
"." << (std::atoi(key.c_str()));
283 }
else if(std::find_if(solverAliases.begin(), solverAliases.end(),
284 [&key_ss, &solverAliases](std::pair<const std::string, int>& entry) {
285 return !solverAliases.empty() && (entry.first == key_ss.str());
287 != solverAliases.end()
290 k << names[0] <<
"." << solverAliases[key_ss.str()];
292 }
else if(value->is_value() || value->is_array()) {
294 std::stringstream solverId;
297 for(
auto&& name : names) {
298 solverId << name <<
".";
302 if(solverId.str().empty()) {
305 MString subString1 = solverId.str().substr(0, solverId.str().size() - 1);
306 MString subString2 = solverId.str().substr(0, solverId.str().find(
'.'));
307 if(subString2 ==
"solver" || subString1 ==
"solver") {
308 if(strstr(key.c_str(),
".") !=
nullptr) {
309 std::stringstream error;
310 error <<
"Setting a solverId inside the solver table environment '" << subString1 <<
"' is prohibited!!! ";
311 TERMM(1, error.str());
319 const char* du = std::strrchr(subString1.c_str(),
'.') + 1;
320 const MInt singleSolverId = std::atoi(du);
321 k << key <<
"." << singleSolverId;
325 std::stringstream error;
326 error <<
"Too many nested tables: " << subString1 <<
" Please use 'solver.solverId' instead!!!";
327 TERMM(1, error.str());
331 std::stringstream error;
332 error <<
"Unknown table type: " << subString2 <<
" Please use 'solver' instead!!!";
333 TERMM(1, error.str());
339 }
else if(value->is_table()) {
341 names.push_back(key);
345 TERMM(1,
"only values, arrays, and tables are supported");
352inline void collectProperties(
const std::shared_ptr<cpptoml::table>& tab, std::vector<Property>& properties,
353 std::map<std::string, int>& solverAliases) {
354 std::vector<std::string> names;
359inline void collectProperties(
const std::shared_ptr<cpptoml::table>& tab, std::vector<Property>& properties) {
360 std::vector<std::string> names;
361 std::map<std::string, int> aliasesdummy;
Class that represents a single key-value pair for TOML properties.
std::vector< MString > m_string
const std::vector< MInt > & asInt() const
const std::vector< MBool > & asBool() const
const std::vector< MFloat > & asFloat() const
Property(MString name_, std::vector< MBool > data)
std::vector< MFloat > m_float
std::vector< MBool > m_bool
const std::vector< MString > & asString() const
MString type2string() const
Property(MString name_, std::vector< MFloat > data)
VariableType type() const
Property(MString name_, std::vector< MInt > data)
Property(MString name_, std::vector< MString > data)
std::vector< MInt > m_int
std::basic_string< char > MString
VariableType value2type(const std::shared_ptr< cpptoml::base > &value)
Obtain type information from TOML value.
void collectProperties(const std::shared_ptr< cpptoml::table > &tab, std::vector< std::string > &names, std::vector< Property > &properties, std::map< std::string, int > &solverAliases)
Recursively traverse TOML table and collect all properties with name, type, and count.
void collectSolverAliases(const std::shared_ptr< cpptoml::table > &tab, std::map< std::string, int > &solverAliases)
Non-recursive search for solver aliases.
Property makeProperty(const MString &name, const std::shared_ptr< cpptoml::base > &item)
Create property from cpptoml item.
Namespace for auxiliary functions/classes.
Type traits for enum type.