14 #include "../core/helicsTime.hpp"
16 # pragma GCC diagnostic push
17 # pragma GCC diagnostic ignored "-Wshadow"
19 #include <string_view>
20 #define TOML11_USING_STRING_VIEW 1
23 # pragma GCC diagnostic pop
29 namespace helics::fileops {
33 toml::value loadToml(
const std::string& tomlString);
35 bool hasTomlExtension(std::string_view tomlString);
39 toml::value loadTomlStr(
const std::string& tomlString);
42 std::string tomlAsString(
const toml::value& element);
45 helics::Time loadTomlTime(
const toml::value& timeElement,
46 time_units defaultUnits = time_units::sec);
49 std::string getName(
const toml::value& element);
53 getOrDefault(
const toml::value& element,
const std::string& key, std::string_view defVal)
55 if (element.contains(key)) {
56 return tomlAsString(element.at(key));
58 return std::string(defVal);
61 inline double getOrDefault(
const toml::value& element,
const std::string& key,
double defVal)
63 return toml::find_or<double>(element, key, defVal);
67 inline bool getOrDefault(
const toml::value& element,
const std::string& key,
bool defVal)
69 return toml::find_or<bool>(element, key, defVal);
73 inline int64_t getOrDefault(
const toml::value& element,
const std::string& key, int64_t defVal)
75 return toml::find_or<int64_t>(element, key, defVal);
79 inline bool callIfMember(
const toml::value& element,
80 const std::string& key,
81 const std::function<
void(
const std::string&)>& call)
83 const std::string empty;
84 auto& val = toml::find_or<std::string>(element, key, empty);
93 inline bool callIfMember(
const toml::value& element,
94 const std::string& key,
95 const std::function<
void(
const std::string&,
helics::Time)>& call)
98 auto val = toml::find_or(element, key, uval);
100 if (!val.is_uninitialized()) {
101 call(key, loadTomlTime(val));
109 inline bool callIfMember(
const toml::value& element,
110 const std::string& key,
111 const std::function<
void(
const std::string&, X)>& call)
114 auto val = toml::find_or(element, key, uval);
115 if (!val.is_uninitialized()) {
116 call(key, toml::get<X>(val));
123 replaceIfMember(
const toml::value& element,
const std::string& key,
helics::Time& timeVal)
126 auto val = toml::find_or(element, key, uval);
128 if (!val.is_uninitialized()) {
129 timeVal = loadTomlTime(val);
133 inline void replaceIfMember(
const toml::value& element,
const std::string& key, std::string& loc)
136 auto val = toml::find_or(element, key, uval);
138 if (!val.is_uninitialized()) {
139 loc = tomlAsString(val);
144 inline void replaceIfMember(
const toml::value& element,
const std::string& key, X& loc)
147 auto val = toml::find_or(element, key, uval);
149 if (!val.is_uninitialized()) {
150 loc = toml::get<X>(val);
155 inline bool isMember(
const toml::value& element,
const std::string& key)
158 auto val = toml::find_or(element, key, uval);
160 return (!val.is_uninitialized());