12 #ifndef SST_CORE_PARAM_H 13 #define SST_CORE_PARAM_H 15 #include "sst/core/from_string.h" 16 #include "sst/core/output.h" 17 #include "sst/core/serialization/serializable.h" 18 #include "sst/core/serialization/serializer.h" 19 #include "sst/core/threadsafe.h" 31 int main(
int argc,
char* argv[]);
36 class ConfigComponent;
37 class SSTModelDescription;
40 class ConfigGraphOutput;
60 bool operator()(
const std::string& X,
const std::string& Y)
const 62 const char* x = X.c_str();
63 const char* y = Y.c_str();
65 #define EAT_VAR(A, B) \ 67 if ( *x == '%' && (*(x + 1) == '(' || *(x + 1) == 'd') ) { \ 73 } while ( *x && *x != ')' ); \ 76 if ( *x != 'd' ) goto NO_VARIABLE; \ 79 while ( *y && isdigit(*y) ) \ 89 if (
'\0' == *x )
return false;
94 if ( *x < *y )
return true;
98 if ( !(*x) && (*y) )
return true;
118 inline T convert_value(
const std::string& key,
const std::string& val)
const 121 return SST::Core::from_string<T>(val);
123 catch (
const std::invalid_argument& e ) {
124 std::string msg =
"Params::find(): No conversion for value: key = " + key +
", value = " + val +
125 ". Original error: " + e.what();
126 std::invalid_argument t(msg);
145 inline T find_impl(
const std::string& k, T default_value,
bool& found)
const 149 const std::string& value = getString(k, found);
150 if ( !found ) {
return default_value; }
152 return convert_value<T>(k, value);
167 inline T find_impl(
const std::string& k,
const std::string& default_value,
bool& found)
const 170 const std::string& value = getString(k, found);
173 return SST::Core::from_string<T>(default_value);
175 catch (
const std::invalid_argument& e ) {
176 std::string msg =
"Params::find(): Invalid default value specified: key = " + k +
177 ", value = " + default_value +
". Original error: " + e.what();
178 std::invalid_argument t(msg);
185 return SST::Core::from_string<T>(value);
187 catch (
const std::invalid_argument& e ) {
188 std::string msg =
"Params::find(): No conversion for value: key = " + k +
", value = " + value +
189 ". Original error: " + e.what();
190 std::invalid_argument t(msg);
196 typedef std::map<uint32_t, std::string>::const_iterator const_iterator;
198 const std::string& getString(
const std::string& name,
bool& found)
const;
223 void cleanToken(std::string& token)
const;
229 void getDelimitedTokens(
const std::string& value,
char delim, std::vector<std::string>& tokens)
const;
244 bool old = verify_enabled;
245 verify_enabled = enable;
320 typename std::enable_if<not std::is_same<std::string, T>::value, T>::type
321 find(
const std::string& k, T default_value,
bool& found)
const 323 return find_impl<T>(k, default_value, found);
337 T
find(
const std::string& k,
const std::string& default_value,
bool& found)
const 339 return find_impl<T>(k, default_value, found);
353 typename std::enable_if<std::is_same<bool, T>::value, T>::type
354 find(
const std::string& k,
const char* default_value,
bool& found)
const 356 if (
nullptr == default_value ) {
return find_impl<T>(k,
static_cast<T
>(0), found); }
357 return find_impl<T>(k, std::string(default_value), found);
369 T
find(
const std::string& k, T default_value)
const 372 return find_impl<T>(k, default_value, tmp);
385 T
find(
const std::string& k,
const std::string& default_value)
const 388 return find_impl<T>(k, default_value, tmp);
402 typename std::enable_if<std::is_same<bool, T>::value, T>::type
403 find(
const std::string& k,
const char* default_value)
const 406 if (
nullptr == default_value ) {
return find_impl<T>(k,
static_cast<T
>(0), tmp); }
407 return find_impl<T>(k, std::string(default_value), tmp);
418 T
find(
const std::string& k)
const 421 T default_value = T();
422 return find_impl<T>(k, default_value, tmp);
436 typename std::enable_if<not std::is_same<bool, T>::value, T>::type
find(
const std::string& k,
bool& found)
const 438 T default_value = T();
439 return find_impl<T>(k, default_value, found);
509 std::string value = getString(k, found);
510 if ( !found )
return;
514 if ( value.front() !=
'[' || value.back() !=
']' ) {
515 vec.push_back(convert_value<T>(k, value));
519 value = value.substr(1, value.size() - 2);
522 std::vector<std::string> tokens;
523 getDelimitedTokens(value,
',', tokens);
526 for (
auto& str : tokens ) {
532 for (
auto& val : tokens ) {
533 vec.push_back(convert_value<T>(k, val));
604 std::string value = getString(k, found);
605 if ( !found )
return;
610 if ( value.find(
"set([") == 0 ) {
615 value = value.substr(4, value.length() - 5);
617 value[value.length() - 1] =
'}';
623 if ( value.front() !=
'{' || value.back() !=
'}' ) {
624 set.insert(convert_value<T>(k, value));
628 value = value.substr(1, value.size() - 2);
631 std::vector<std::string> tokens;
632 getDelimitedTokens(value,
',', tokens);
635 for (
auto& str : tokens ) {
641 for (
auto& val : tokens ) {
642 set.insert(convert_value<T>(k, val));
710 template <
class keyT,
class valT>
716 std::string value = getString(k, found);
717 if ( !found )
return;
720 if ( value.front() !=
'{' || value.back() !=
'}' ) {
721 std::string msg =
"Invalid format for parameter to be parsed as a map: " + value;
724 throw std::invalid_argument(msg);
727 value = value.substr(1, value.size() - 2);
730 std::vector<std::string> tokens;
731 getDelimitedTokens(value,
',', tokens);
735 std::vector<std::string> kvpair;
736 for (
auto& x : tokens ) {
738 getDelimitedTokens(x,
':', kvpair);
740 if ( kvpair.size() != 2 ) {
741 std::string msg =
"Invalid format for map key/value pair: " + x;
744 throw std::invalid_argument(msg);
748 cleanToken(kvpair[0]);
749 cleanToken(kvpair[1]);
752 map[convert_value<keyT>(k, kvpair[0])] = convert_value<valT>(k, kvpair[1]);
767 std::string value = getString(k, found);
768 if ( !found )
return false;
770 if ( (value.find(
"[") == std::string::npos) || (value.find(
"]") == std::string::npos) ) {
return false; }
775 void print_all_params(std::ostream& os,
const std::string& prefix =
"")
const;
779 std::string
toString(
const std::string& prefix =
"")
const;
791 void insert(
const std::string& key,
const std::string& value,
bool overwrite =
true);
806 std::set<std::string>
getKeys()
const;
894 static std::map<std::string, std::string>
getGlobalParamSet(
const std::string& name);
934 std::map<uint32_t, std::string> my_data;
935 std::vector<std::map<uint32_t, std::string>*> data;
936 std::vector<KeySet_t> allowedKeys;
938 static bool g_verify_enabled;
940 static uint32_t getKey(
const std::string& str);
950 friend int ::main(
int argc,
char* argv[]);
954 static std::map<std::string, uint32_t> keyMap;
955 static std::vector<std::string> keyMapReverse;
958 static uint32_t nextKeyID;
960 static std::map<std::string, std::map<uint32_t, std::string>> global_params;
966 #define SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(type) \ 968 type Params::find(const std::string& k, type default_value, bool& found) const; \ 970 type Params::find(const std::string& k, const std::string& default_value, bool& found) const; \ 972 type Params::find(const std::string& k, type default_value) const; \ 974 type Params::find(const std::string& k, const std::string& default_value) const; \ 976 type Params::find(const std::string& k) const; 979 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int32_t)
980 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint32_t)
981 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int64_t)
982 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint64_t)
983 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
bool)
984 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
float)
985 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
double)
986 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(UnitAlgebra)
991 std::string Params::find<std::string>(
const std::string& k,
const std::string& default_value,
bool &found)
const;
996 #endif // SST_CORE_PARAMS_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:53
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
void print_all_params(std::ostream &os, const std::string &prefix="") const
Print all key/value parameter pairs to specified ostream.
Definition: params.cc:100
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.
Definition: params.h:354
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.
Definition: params.h:369
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.
Definition: params.h:385
Outputs configuration data to a specified file path.
Definition: configGraphOutput.h:54
Represents the configuration of a generic component.
Definition: configGraph.h:217
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:226
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:389
static void enableVerify()
Enable, on a global scale, parameter verification.
Definition: params.h:254
bool contains(const key_type &k) const
Search the container for a particular key.
Definition: params.cc:217
Definition: serializable.h:24
static const std::string & getParamName(uint32_t id)
Given a Parameter Key ID, return the Name of the matching parameter.
Definition: params.cc:263
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.
Definition: params.h:504
void clear()
Erases all elements, including deleting reference to global param sets.
Definition: params.cc:81
std::vector< std::string > getLocalKeys() const
Get a vector of the local keys.
Definition: params.cc:447
Params()
Create a new, empty Params.
Definition: params.cc:55
std::vector< std::string > getSubscribedGlobalParamSets() const
Get a vector of the global param sets this Params object is subscribed to.
Definition: params.cc:459
bool enableVerify(bool enable)
Enable or disable parameter verification on an instance of Params.
Definition: params.h:242
Main control class for a SST Simulation.
Definition: simulation_impl.h:76
static std::vector< std::string > getGlobalParamSetNames()
Get a vector of the names of available global parameter sets.
Definition: params.cc:435
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.
Definition: params.h:436
std::string toString(const std::string &prefix="") const
Return a string version of all key/value parameter pairs.
Definition: params.cc:140
Params get_scoped_params(const std::string &scope) const
Returns a new parameter object with parameters that match the specified scoped prefix (scopes are sep...
Definition: params.cc:198
std::set< std::string > getKeys() const
Get all the keys contained in the Params object.
Definition: params.cc:186
Definition: threadsafe.h:121
void find_set(const key_type &k, std::set< T > &set) const
Find a Parameter value in the set, and return its value as a set of T's.
Definition: params.h:599
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.
Definition: params.h:321
Parameter store.
Definition: params.h:55
static void insert_global(const std::string &set, const key_type &key, const key_type &value, bool overwrite=true)
Adds a key/value pair to the specified global set.
Definition: params.cc:319
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:232
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.
Definition: params.h:337
void find_map(const key_type &k, std::map< keyT, valT > &map) const
Find a Parameter value in the set, and return its value as a map<keyT,valT>.
Definition: params.h:711
Base class for Model Generation.
Definition: sstmodel.h:25
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:233
std::string key_type
Definition: params.h:232
size_t count(const key_type &k) const
Finds the number of elements with given key.
Definition: params.cc:89
bool empty() const
Returns true if the Params is empty.
Definition: params.cc:50
T find(const std::string &k) const
Find a Parameter value in the set, and return its value as a type T.
Definition: params.h:418
void verifyKey(const key_type &k) const
Definition: params.cc:241
void addGlobalParamSet(const std::string &set)
Adds a global param set to be looked at in this Params object if the key isn't found locally...
Definition: params.cc:310
size_t size() const
Returns the size of the Params.
Definition: params.cc:44
Params & operator=(const Params &old)
Assignment operator.
Definition: params.cc:70
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.
Definition: params.h:764
void insert(const std::string &key, const std::string &value, bool overwrite=true)
Add a key/value pair into the param object.
Definition: params.cc:163
void verifyParam(const key_type &k) const
Definition: params.cc:257
static std::map< std::string, std::string > getGlobalParamSet(const std::string &name)
Get a named global parameter set.
Definition: params.cc:422
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.
Definition: params.h:403