14 #include "../core/helicsTime.hpp"
16 # pragma GCC diagnostic push
17 # pragma GCC diagnostic ignored "-Wshadow"
21 # pragma GCC diagnostic pop
27 namespace helics::fileops {
31 toml::value loadToml(
const std::string& tomlString);
33 bool hasTomlExtension(
const std::string& tomlString);
36 toml::value loadTomlStr(
const std::string& tomlString);
39 std::string tomlAsString(
const toml::value& element);
42 helics::Time loadTomlTime(
const toml::value& timeElement,
43 time_units defaultUnits = time_units::sec);
46 std::string getName(
const toml::value& element);
50 getOrDefault(
const toml::value& element,
const std::string& key,
const std::string& defVal)
52 if (element.contains(key)) {
53 return tomlAsString(element.at(key));
58 inline double getOrDefault(
const toml::value& element,
const std::string& key,
double defVal)
60 return toml::find_or<double>(element, key, defVal);
64 inline bool getOrDefault(
const toml::value& element,
const std::string& key,
bool defVal)
66 return toml::find_or<bool>(element, key, defVal);
70 inline int64_t getOrDefault(
const toml::value& element,
const std::string& key, int64_t defVal)
72 return toml::find_or<int64_t>(element, key, defVal);
76 inline bool callIfMember(
const toml::value& element,
77 const std::string& key,
78 const std::function<
void(
const std::string&)>& call)
80 const std::string empty;
81 auto& val = toml::find_or<std::string>(element, key, empty);
90 inline bool callIfMember(
const toml::value& element,
91 const std::string& key,
92 const std::function<
void(
const std::string&,
helics::Time)>& call)
95 auto val = toml::find_or(element, key, uval);
97 if (!val.is_uninitialized()) {
98 call(key, loadTomlTime(val));
106 inline bool callIfMember(
const toml::value& element,
107 const std::string& key,
108 const std::function<
void(
const std::string&, X)>& call)
111 auto val = toml::find_or(element, key, uval);
112 if (!val.is_uninitialized()) {
113 call(key, toml::get<X>(val));
120 replaceIfMember(
const toml::value& element,
const std::string& key,
helics::Time& timeVal)
123 auto val = toml::find_or(element, key, uval);
125 if (!val.is_uninitialized()) {
126 timeVal = loadTomlTime(val);
130 inline void replaceIfMember(
const toml::value& element,
const std::string& key, std::string& loc)
133 auto val = toml::find_or(element, key, uval);
135 if (!val.is_uninitialized()) {
136 loc = tomlAsString(val);
141 inline void replaceIfMember(
const toml::value& element,
const std::string& key, X& loc)
144 auto val = toml::find_or(element, key, uval);
146 if (!val.is_uninitialized()) {
147 loc = toml::get<X>(val);
152 inline bool isMember(
const toml::value& element,
const std::string& key)
155 auto val = toml::find_or(element, key, uval);
157 return (!val.is_uninitialized());