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);
37 bool looksLikeConfigToml(std::string_view tomlString);
48 time_units defaultUnits = time_units::sec);
51 std::string getName(
const toml::value& element);
55 getOrDefault(
const toml::value& element,
const std::string& key, std::string_view defVal)
57 if (element.contains(key)) {
60 return std::string(defVal);
63 inline double getOrDefault(
const toml::value& element,
const std::string& key,
double defVal)
65 return toml::find_or<double>(element, key, defVal);
69 inline bool getOrDefault(
const toml::value& element,
const std::string& key,
bool defVal)
71 return toml::find_or<bool>(element, key, defVal);
75 inline int64_t getOrDefault(
const toml::value& element,
const std::string& key, int64_t defVal)
77 return toml::find_or<int64_t>(element, key, defVal);
81 inline bool callIfMember(
const toml::value& element,
82 const std::string& key,
83 const std::function<
void(
const std::string&)>& call)
85 const std::string empty;
86 auto& val = toml::find_or<std::string>(element, key, empty);
95 inline bool callIfMember(
const toml::value& element,
96 const std::string& key,
97 const std::function<
void(
const std::string&,
helics::Time)>& call)
100 auto val = toml::find_or(element, key, uval);
102 if (!val.is_uninitialized()) {
111 inline bool callIfMember(
const toml::value& element,
112 const std::string& key,
113 const std::function<
void(
const std::string&, X)>& call)
116 auto val = toml::find_or(element, key, uval);
117 if (!val.is_uninitialized()) {
118 call(key, toml::get<X>(val));
125 replaceIfMember(
const toml::value& element,
const std::string& key,
helics::Time& timeVal)
128 auto val = toml::find_or(element, key, uval);
130 if (!val.is_uninitialized()) {
131 timeVal = loadTomlTime(val);
135 inline void replaceIfMember(
const toml::value& element,
const std::string& key, std::string& loc)
138 auto val = toml::find_or(element, key, uval);
140 if (!val.is_uninitialized()) {
146 inline void replaceIfMember(
const toml::value& element,
const std::string& key, X& loc)
149 auto val = toml::find_or(element, key, uval);
151 if (!val.is_uninitialized()) {
152 loc = toml::get<X>(val);
157 inline bool isMember(
const toml::value& element,
const std::string& key)
160 auto val = toml::find_or(element, key, uval);
162 return (!val.is_uninitialized());
toml::value loadTomlStr(const std::string &tomlString)
toml::value loadToml(const std::string &tomlString)
helics::Time loadTomlTime(const toml::value &timeElement, time_units defaultUnits=time_units::sec)
std::string tomlAsString(const toml::value &element)
bool isMember(const toml::value &element, const std::string &key)
Definition: TomlProcessingFunctions.hpp:157
TimeRepresentation< count_time< 9 > > Time
Definition: helicsTime.hpp:27