1 #ifndef MHO_ParameterStore_HH__
2 #define MHO_ParameterStore_HH__
67 void Dump() { std::cout << fStore.dump(2) << std::endl; }
103 template<
typename XValueType >
bool Set(
const std::string& value_path,
const XValueType&
value);
114 fStore[mho_json::json_pointer(SanitizePath(value_path))] =
value;
131 template<
typename XValueType >
bool Get(
const std::string& value_path, XValueType&
value)
const;
140 template<
typename XValueType > XValueType
GetAs(
const std::string& value_path)
const;
149 template<
typename XValueType > XValueType
GetRequiredAs(
const std::string& value_path)
const;
160 std::string path = SanitizePath(value_path);
166 for(
auto it = fPath.begin(); it != fPath.end(); it++)
168 auto jit = p->find(*it);
173 else if(*it == *(fPath.rbegin()))
192 std::string SanitizePath(
const std::string& value_path)
const
195 if(vpath.size() > 0 && vpath.back() ==
'/')
203 mutable MHO_Tokenizer fTokenizer;
204 mutable std::vector< std::string > fPath;
220 std::string path = SanitizePath(value_path);
230 for(
auto it = fPath.begin(); it != fPath.end(); it++)
232 if(*it != *(fPath.rbegin()))
266 std::string path = SanitizePath(value_path);
271 bool present =
false;
273 for(
auto it = fPath.begin(); it != fPath.end(); it++)
275 auto jit = p->find(*it);
280 else if(*it == *(fPath.rbegin()))
282 value = jit->get< XValueType >();
301 XValueType v = XValueType();
302 bool ok =
Get(value_path, v);
305 msg_error(
"utility",
"failed to retrieve value for: " << value_path <<
" returning a default value" << eom);
312 XValueType v = XValueType();
313 bool ok =
Get(value_path, v);
316 msg_fatal(
"utility",
"failed to retrieve value: " << value_path <<
", aborting" << eom);
#define msg_fatal(xKEY, xCONTENT)
Definition: MHO_Message.hh:228
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
#define HOPS_THROW
Definition: MHO_TestAssertions.hh:19
Class MHO_ParameterStore.
Definition: MHO_ParameterStore.hh:53
~MHO_ParameterStore()
Definition: MHO_ParameterStore.hh:62
bool Set(const std::string &value_path, const XValueType &value)
Setter for value at specified path in the parameter store.
Definition: MHO_ParameterStore.hh:217
void Dump()
Dumps the store JSON data to std:cout (for debugging)
Definition: MHO_ParameterStore.hh:67
void ClearData()
Clears all data from fStore.
Definition: MHO_ParameterStore.hh:93
void FillData(const mho_json &data)
Stores input json data for later use.
Definition: MHO_ParameterStore.hh:88
MHO_ParameterStore()
Definition: MHO_ParameterStore.hh:55
void DumpData(mho_json &data)
Copies data from internal storage to provided json object.
Definition: MHO_ParameterStore.hh:81
XValueType GetAs(const std::string &value_path) const
Getter, cast to type, always returns a value, if not found the value returned is XValueType()
Definition: MHO_ParameterStore.hh:299
XValueType GetRequiredAs(const std::string &value_path) const
Getter, cast to type, throws an error if the path/value is not present, will not return a default.
Definition: MHO_ParameterStore.hh:310
bool Get(const std::string &value_path, XValueType &value) const
Retrieves a value by path and returns it as XValueType, using default constructor if not found.
Definition: MHO_ParameterStore.hh:262
bool IsPresent(const std::string &value_path) const
Function IsPresent, checks if path is present in parameter store.
Definition: MHO_ParameterStore.hh:158
void CopyFrom(const MHO_ParameterStore ©)
Copies the parameter store from a given source.
Definition: MHO_ParameterStore.hh:74
bool Set(const std::string &value_path, const mho_json &value)
Explicit overload for mho_json values. Uses nlohmann::json_pointer to avoid template deduction ambigu...
Definition: MHO_ParameterStore.hh:110
void SetIncludeEmptyTokensFalse()
Definition: MHO_Tokenizer.cc:30
void SetString(const std::string *aString)
Definition: MHO_Tokenizer.cc:65
void GetTokens(std::vector< std::string > *tokens)
Definition: MHO_Tokenizer.cc:75
static std::string TrimLeadingAndTrailingWhitespace(const std::string &value)
Definition: MHO_Tokenizer.cc:283
void SetRemoveLeadingTrailingWhitespaceTrue()
Setter for remove leading trailing whitespace true.
Definition: MHO_Tokenizer.cc:55
void SetDelimiter(const std::string &aDelim)
Definition: MHO_Tokenizer.cc:70
Definition: MHO_AdhocFlagging.hh:18