14 #include "../core/helics-time.hpp"
16 #include "json/json.h"
25 Json::Value
loadJson(
const std::string& jsonString);
29 Json::Value
loadJsonStr(
const std::string& jsonString);
33 time_units defaultUnits = time_units::sec);
36 std::string
getKey(
const Json::Value& element);
41 inline std::string JsonAsString(
const Json::Value& element)
47 getOrDefault(
const Json::Value& element,
const std::string& key,
const std::string& defVal)
49 return (element.isMember(key)) ? JsonAsString(element[key]) : defVal;
52 inline double getOrDefault(
const Json::Value& element,
const std::string& key,
double defVal)
54 return (element.isMember(key)) ? element[key].asDouble() : defVal;
57 inline bool getOrDefault(
const Json::Value& element,
const std::string& key,
bool defVal)
59 return (element.isMember(key)) ? element[key].asBool() : defVal;
62 inline int64_t getOrDefault(
const Json::Value& element,
const std::string& key, int64_t defVal)
64 return (element.isMember(key)) ? element[key].asInt64() : defVal;
67 inline bool callIfMember(
const Json::Value& element,
68 const std::string& key,
69 const std::function<
void(
const std::string&,
helics::Time)>& call)
71 if (element.isMember(key)) {
78 inline bool callIfMember(
const Json::Value& element,
79 const std::string& key,
80 const std::function<
void(
const std::string&,
bool)>& call)
82 if (element.isMember(key)) {
83 call(key, element[key].asBool());
89 inline bool callIfMember(
const Json::Value& element,
90 const std::string& key,
91 const std::function<
void(
const std::string&,
int)>& call)
93 if (element.isMember(key)) {
94 call(key, element[key].asInt());
100 inline bool callIfMember(
const Json::Value& element,
101 const std::string& key,
102 const std::function<
void(
const std::string&)>& call)
104 if (element.isMember(key)) {
105 call(element[key].asString());
112 replaceIfMember(
const Json::Value& element,
const std::string& key,
helics::Time& timeVal)
114 if (element.isMember(key)) {
119 inline void replaceIfMember(
const Json::Value& element,
const std::string& key, std::string& sval)
121 if (element.isMember(key)) {
122 sval = element[key].asString();
126 inline void replaceIfMember(
const Json::Value& element,
const std::string& key,
bool& bval)
128 if (element.isMember(key)) {
129 bval = element[key].asBool();
133 inline void replaceIfMember(
const Json::Value& element,
const std::string& key,
int& sval)
135 if (element.isMember(key)) {
136 sval = element[key].asInt();