SST
10.1.0
StructuralSimulationToolkit
|
Parameter store. More...
#include <params.h>
Public Types | |
typedef std::string | key_type |
typedef std::set< key_type, KeyCompare > | KeySet_t |
Public Member Functions | |
bool | enableVerify (bool enable) |
Enable or disable parameter verification on an instance of Params. More... | |
size_t | size () const |
Returns the size of the Params. More... | |
bool | empty () const |
Returns true if the Params is empty. More... | |
Params () | |
Create a new, empty Params. | |
Params (const Params &old) | |
Create a copy of a Params object. | |
Params & | operator= (const Params &old) |
Assignment operator. More... | |
void | clear () |
Erases all elements. | |
size_t | count (const key_type &k) |
Finds the number of elements with given key. More... | |
template<class T > | |
std::enable_if< not std::is_same< std::string, T > ::value, T >::type | find (const std::string &k, T default_value, bool &found) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
T | find (const std::string &k, const std::string &default_value, bool &found) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
std::enable_if< std::is_same < bool, T >::value, T >::type | find (const std::string &k, const char *default_value, bool &found) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
T | find (const std::string &k, T default_value) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
T | find (const std::string &k, const std::string &default_value) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
std::enable_if< std::is_same < bool, T >::value, T >::type | find (const std::string &k, const char *default_value) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
T | find (const std::string &k) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
std::enable_if< not std::is_same< bool, T >::value, T >::type | find (const std::string &k, bool &found) const |
Find a Parameter value in the set, and return its value as a type T. More... | |
template<class T > | |
void | find_array (const key_type &k, std::vector< T > &vec) const |
Find a Parameter value in the set, and return its value as a vector of T's. More... | |
bool | is_value_array (const key_type &k) const |
Checks to see if the value associated with the given key is considered to be an array. More... | |
void | print_all_params (std::ostream &os, const std::string &prefix="") const |
Print all key/value parameter pairs to specified ostream. | |
void | print_all_params (Output &out, const std::string &prefix="") const |
void | insert (const std::string &key, const std::string &value, bool overwrite=true) |
Add a key value pair into the param object. | |
void | insert (const Params ¶ms) |
std::set< std::string > | getKeys () const |
Params | find_prefix_params (const std::string &prefix) const |
Returns a new parameter object with parameters that match the specified prefix. | |
Params | find_scoped_params (const std::string &scope, const char *delims=".:") const |
bool | contains (const key_type &k) |
void | pushAllowedKeys (const KeySet_t &keys) |
void | popAllowedKeys () |
Removes the most recent set of keys considered allowed. | |
void | verifyParam (const key_type &k) const |
void | serialize_order (SST::Core::Serialization::serializer &ser) override |
Public Member Functions inherited from SST::Core::Serialization::serializable | |
virtual const char * | cls_name () const =0 |
virtual uint32_t | cls_id () const =0 |
virtual std::string | serialization_name () const =0 |
Static Public Member Functions | |
static void | enableVerify () |
Enable, on a global scale, parameter verification. More... | |
static const std::string & | getParamName (uint32_t id) |
Given a Parameter Key ID, return the Name of the matching parameter. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from SST::Core::Serialization::serializable | |
static constexpr uint32_t | NullClsId = std::numeric_limits<uint32_t>::max() |
Protected Types inherited from SST::Core::Serialization::serializable | |
enum | cxn_flag_t { ConstructorFlag } |
Static Protected Member Functions inherited from SST::Core::Serialization::serializable | |
static void | serializable_abort (uint32_t line, const char *file, const char *func, const char *obj) |
Parameter store.
Stores key-value pairs as std::strings and provides a templated find method for finding values and converting them to arbitrary types (
typedef std::string SST::Params::key_type |
Type of key (string)
typedef std::set<key_type, KeyCompare> SST::Params::KeySet_t |
Type of a set of keys
bool SST::Params::contains | ( | const key_type & | k | ) |
k | Key to search for |
size_t SST::Params::count | ( | const key_type & | k | ) |
Finds the number of elements with given key.
k | Key of (key, value) pairs to be located. |
bool SST::Params::empty | ( | ) | const |
Returns true if the Params is empty.
(Thus begin() would equal end().)
|
inline |
Enable or disable parameter verification on an instance of Params.
Useful when generating a new set of Params to pass off to a module.
Referenced by find_prefix_params().
|
inlinestatic |
Enable, on a global scale, parameter verification.
Used after construction of the config graph so that warnings are not generated during construction.
Referenced by SST::Simulation::performWireUp().
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type (including bool) , a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found |
found | - set to true if the the parameter was found |
std::invalid_argument | If value in (key, value) can't be converted to type T, an invalid_argument exception is thrown. |
Referenced by SST::Statistics::StatisticOutputJSON::checkOutputParameters(), SST::Statistics::StatisticOutputConsole::checkOutputParameters(), SST::Statistics::StatisticOutputTxt::checkOutputParameters(), SST::Statistics::StatisticOutputCSV::checkOutputParameters(), and SST::Statistics::StatisticBase::StatisticBase().
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type (including bool) , a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found, specified as a string |
found | - set to true if the the parameter was found |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
This version of find is only enabled for bool. This is required because a string literal will be preferentially cast to a bool rather than a string. This ensures that find<bool> works correctly for string literals. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found, specified as a string literal |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type (including bool), a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type (including bool) , a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found, specified as a string |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
This version of find is only enabled for bool. This is required because a string literal will be preferentially cast to a bool rather than a string. This ensures that find<bool> works correctly for string literals.This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
default_value | - Default value to return if parameter isn't found, specified as a string literal |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type (including bool) , a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
|
inline |
Find a Parameter value in the set, and return its value as a type T.
Type T must be either a basic numeric type , a std::string, or a class that has a constructor with a std::string as its only parameter. This version of find is not enabled for bool as it conflicts with find<bool>(string key, bool default_value). This class uses SST::Core::from_string to do the conversion.
k | - Parameter name |
found | - set to true if the the parameter was found |
|
inline |
Find a Parameter value in the set, and return its value as a vector of T's.
The array will be appended to the end of the vector.
Type T must be either a basic numeric type (including bool) , a std::string, or a class that has a constructor with a std::string as its only parameter. This class uses SST::Core::from_string to do the conversion. The values in the array must be enclosed in square brackets ( [] ), and be comma separated (commas in double or single quotes will not be considered a delimiter). If there are no square brackets, the entire string will be considered one value and a single item will be added to the vector.
More details about parsing the values out of the string:
Parses a string representing an array of tokens. It is tailored to the types strings you get when passing a python list as the param string. When you call addParam() on a python list in the input file, it will call the str() function on the list, which creates a string with the following format: [item1, item2, item3]
The format of the items depends on where they came from. The string for the items are generated by calling the repr() function on them. For strings, this means they will typically be enclosed in single quotes. It is possible that they end up enclosed in double quotes if the string itself contains a single quote. For strings which contain both single and double quotes, the repr() will create a single quoted string with all internal single quotes escaped with '\'. Most other items used in SST do not enclose the string in quotes, though any string that contains a comma would need to be enclosed in quotes, since the comma is the delimiter character used. This is not done automatically, so if you have something that generates a commma in the string created by repr(), you may need to create an array string manually. Also, any string that starts with a quote character, must end with the same quote character.
Tokens are generated by splitting the string on commas that are not within quotes (double or single). All whitespace at the beginning and end of a token is ignored (unless inside quotes). Once the tokens are generated, any quoted string will have the front and back quotes removed. The '\' for any escaped quote of the same type as the front and back is also removed.
Examples:
These will produce the same results: [1, 2, 3, 4, 5] ['1', '2', '3', '4', '5']
Examples of strings using double and/or single quotes: 'This is "a" test' -> This is "a" test "This is 'a' test" -> This is 'a' test 'This "is \'a\'" test' -> This "is 'a'" test 'This "is \"a"" test' -> This "is "a"" test
k | - Parameter name |
vec | - vector to append array items to |
References verifyParam().
|
static |
Given a Parameter Key ID, return the Name of the matching parameter.
id | Key ID to look up |
|
inline |
Checks to see if the value associated with the given key is considered to be an array.
A value is considered to be an array if it is enclosed in square brackets ([]). No whitespace before or after the brackets is allowed.
k | - Parameter name |
Assignment operator.
old | Param to be copied |
All the elements of old are copied,
void SST::Params::pushAllowedKeys | ( | const KeySet_t & | keys | ) |
keys | Set of keys to consider valid to add to the stack of legal keys |
Referenced by SST::Factory::Create(), SST::Factory::CreateComponent(), SST::Factory::CreateModule(), and SST::Factory::CreateModuleWithComponent().
size_t SST::Params::size | ( | ) | const |
Returns the size of the Params.
void SST::Params::verifyParam | ( | const key_type & | k | ) | const |
k | Key to check for validity |
References SST::Output::output(), and SST::Output::STDERR.
Referenced by find_array().