Class MHO_ParameterStore.
More...
#include <MHO_ParameterStore.hh>
|
| MHO_ParameterStore () |
|
| ~MHO_ParameterStore () |
|
void | ClearData () |
| Clears all data from fStore. More...
|
|
void | CopyFrom (const MHO_ParameterStore ©) |
| Copies the parameter store from a given source. More...
|
|
void | Dump () |
| Dumps the store JSON data to std:cout (for debugging) More...
|
|
void | DumpData (mho_json &data) |
| Copies data from internal storage to provided json object. More...
|
|
void | FillData (const mho_json &data) |
| Stores input json data for later use. More...
|
|
template<typename XValueType > |
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. More...
|
|
template<typename XValueType > |
XValueType | GetAs (const std::string &value_path) const |
| Function IsPresent. More...
|
|
bool | IsPresent (const std::string &value_path) const |
|
template<typename XValueType > |
bool | Set (const std::string &value_path, const XValueType &value) |
| Setter for value at specified path in the parameter store. More...
|
|
Class MHO_ParameterStore.
class to store parameters (typically from control file) for later retrieval There are some deficiencies with this json-based approach, for example everything except terminal values must be named objects (no lists allowed), though maybe we don't really need that functionality TODO – allow for variable keys in the value path. Sometimes the name of an item is found within the value of another item, so it would be useful to extract that name, and substitute it into the value path for the item of interest. For example consider the following structure: {
- Date
- Wed Jun 7 23:42:31 2023 -0400
- Author
- J. Barrett - barre.nosp@m.ttj@.nosp@m.mit.e.nosp@m.du
"item0":
{
"key1": "kvalue1",
"key2": "kvalue2"
};
"item1":
{
"kvalue1": "value3",
"kvalue2":
{
"key3": "value4",
"key5": "value5"
}
}
} Let's say we wanted to access 'value4', but didn't know the name of the key "kvalue2", (only item1 and key3) but knew it could be located under item1 via a key specified by the value associated with "item0/key2" Then a useful construction to retrieve this would be something like the following (with the variable key's location within braces): std::string vpath = "/item1/{/item0/key2}/key3" --> this gets translated into "/item1/kvalue2/key3" before retrieval auto value = params.Get<std::string>(vpath);
◆ MHO_ParameterStore()
hops::MHO_ParameterStore::MHO_ParameterStore |
( |
| ) |
|
|
inline |
◆ ~MHO_ParameterStore()
hops::MHO_ParameterStore::~MHO_ParameterStore |
( |
| ) |
|
|
inline |
◆ ClearData()
void hops::MHO_ParameterStore::ClearData |
( |
| ) |
|
|
inline |
Clears all data from fStore.
◆ CopyFrom()
Copies the parameter store from a given source.
- Parameters
-
◆ Dump()
void hops::MHO_ParameterStore::Dump |
( |
| ) |
|
|
inline |
Dumps the store JSON data to std:cout (for debugging)
◆ DumpData()
void hops::MHO_ParameterStore::DumpData |
( |
mho_json & |
data | ) |
|
|
inline |
Copies data from internal storage to provided json object.
- Parameters
-
data | Output parameter to store copied json data. |
◆ FillData()
void hops::MHO_ParameterStore::FillData |
( |
const mho_json & |
data | ) |
|
|
inline |
Stores input json data for later use.
- Parameters
-
data | Input json data to be stored. |
◆ Get()
template<typename XValueType >
bool hops::MHO_ParameterStore::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.
Retrieves a value from the parameter store by path and returns it as XValueType.
- Template Parameters
-
XValueType | Template parameter XValueType |
- Parameters
-
value_path | Path to the value to retrieve |
value | (XValueType&) |
- Returns
- XValueType value or default constructed value if not found
- Parameters
-
value_path | Path to the value in the parameter store |
value | (XValueType&) |
- Returns
- True if retrieval was successful, false otherwise
◆ GetAs()
template<typename XValueType >
XValueType hops::MHO_ParameterStore::GetAs |
( |
const std::string & |
value_path | ) |
const |
Function IsPresent.
Retrieves and returns a value as specified type from the parameter store using the given path.
- Template Parameters
-
XValueType | Template parameter XValueType |
- Parameters
-
value_path | (const std::string&) |
- Returns
- Return value (bool)
Getter for as
- Template Parameters
-
XValueType | Template parameter XValueType |
- Parameters
-
value_path | Path to retrieve value from |
- Returns
- Value of type XValueType retrieved from path or default if not found
- Parameters
-
value_path | Path to the desired value in the parameter store |
- Returns
- Value retrieved as specified template type or default value if retrieval fails
◆ IsPresent()
bool hops::MHO_ParameterStore::IsPresent |
( |
const std::string & |
value_path | ) |
const |
|
inline |
◆ Set()
template<typename XValueType >
bool hops::MHO_ParameterStore::Set |
( |
const std::string & |
value_path, |
|
|
const XValueType & |
value |
|
) |
| |
Setter for value at specified path in the parameter store.
Function MHO_ParameterStore::Set.
- Parameters
-
value_path | Path to the value as a string reference. |
value | Value to set at the given path. |
- Returns
- True if value was successfully set, false otherwise.
- Parameters
-
value_path | (const std::string&) |
value | (const XValueType&) |
- Returns
- Return value (template< typename XValueType > bool)
The documentation for this class was generated from the following file: