HOPS
HOPS class reference
Public Member Functions | List of all members
hops::MHO_ParameterStore Class Reference

Class MHO_ParameterStore. More...

#include <MHO_ParameterStore.hh>

Public Member Functions

 MHO_ParameterStore ()
 
 ~MHO_ParameterStore ()
 
void ClearData ()
 Clears all data from fStore. More...
 
void CopyFrom (const MHO_ParameterStore &copy)
 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...
 

Detailed Description

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);

Constructor & Destructor Documentation

◆ MHO_ParameterStore()

hops::MHO_ParameterStore::MHO_ParameterStore ( )
inline

◆ ~MHO_ParameterStore()

hops::MHO_ParameterStore::~MHO_ParameterStore ( )
inline

Member Function Documentation

◆ ClearData()

void hops::MHO_ParameterStore::ClearData ( )
inline

Clears all data from fStore.

◆ CopyFrom()

void hops::MHO_ParameterStore::CopyFrom ( const MHO_ParameterStore copy)
inline

Copies the parameter store from a given source.

Parameters
copyReference to the MHO_ParameterStore object to copy from.

◆ 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
dataOutput 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
dataInput 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
XValueTypeTemplate parameter XValueType
Parameters
value_pathPath to the value to retrieve
value(XValueType&)
Returns
XValueType value or default constructed value if not found
Parameters
value_pathPath 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
XValueTypeTemplate parameter XValueType
Parameters
value_path(const std::string&)
Returns
Return value (bool)

Getter for as

Template Parameters
XValueTypeTemplate parameter XValueType
Parameters
value_pathPath to retrieve value from
Returns
Value of type XValueType retrieved from path or default if not found
Parameters
value_pathPath 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_pathPath to the value as a string reference.
valueValue 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: