12 #ifndef SST_CORE_PARAM_H 13 #define SST_CORE_PARAM_H 15 #include "sst/core/from_string.h" 16 #include "sst/core/serialization/serializable.h" 17 #include "sst/core/serialization/serializer.h" 18 #include "sst/core/threadsafe.h" 33 #include <type_traits> 37 int main(
int argc,
char* argv[]);
42 class ConfigComponent;
43 class ConfigPortModule;
45 class SSTModelDescription;
48 class ConfigGraphOutput;
68 bool operator()(
const std::string& X,
const std::string& Y)
const 70 const char* x = X.c_str();
71 const char* y = Y.c_str();
73 #define EAT_VAR(A, B) \ 75 if ( *x == '%' && (*(x + 1) == '(' || *(x + 1) == 'd') ) { \ 81 } while ( *x && *x != ')' ); \ 84 if ( *x != 'd' ) goto NO_VARIABLE; \ 87 while ( *y && isdigit(*y) ) \ 97 if (
'\0' == *x )
return false;
102 if ( *x < *y )
return true;
105 }
while ( *x && *y );
106 if ( !(*x) && (*y) )
return true;
126 inline T convert_value(
const std::string& key,
const std::string& val)
const 129 return SST::Core::from_string<T>(val);
131 catch (
const std::invalid_argument& e ) {
132 std::string msg =
"Params::find(): No conversion for value: key = " + key +
", value = " + val +
133 ". Original error: " + e.what();
134 std::invalid_argument t(msg);
153 inline T find_impl(
const std::string& k, T default_value,
bool& found)
const 157 const std::string& value = getString(k, found);
159 return default_value;
162 return convert_value<T>(k, value);
177 inline T find_impl(
const std::string& k,
const std::string& default_value,
bool& found)
const 180 const std::string& value = getString(k, found);
183 return SST::Core::from_string<T>(default_value);
185 catch (
const std::invalid_argument& e ) {
186 std::string msg =
"Params::find(): Invalid default value specified: key = " + k +
187 ", value = " + default_value +
". Original error: " + e.what();
188 std::invalid_argument t(msg);
195 return SST::Core::from_string<T>(value);
197 catch (
const std::invalid_argument& e ) {
198 std::string msg =
"Params::find(): No conversion for value: key = " + k +
", value = " + value +
199 ". Original error: " + e.what();
200 std::invalid_argument t(msg);
206 using const_iterator = std::map<uint32_t, std::string>::const_iterator;
208 const std::string& getString(
const std::string& name,
bool& found)
const;
233 void cleanToken(std::string& token)
const;
239 void getDelimitedTokens(
const std::string& value,
char delim, std::vector<std::string>& tokens)
const;
254 bool old = verify_enabled;
255 verify_enabled = enable;
266 g_verify_enabled =
true;
333 std::enable_if_t<!std::is_same_v<std::string, T>, T>
find(
const std::string& k, T default_value,
bool& found)
const 335 return find_impl<T>(k, default_value, found);
349 T
find(
const std::string& k,
const std::string& default_value,
bool& found)
const 351 return find_impl<T>(k, default_value, found);
365 std::enable_if_t<std::is_same_v<bool, T>, T>
find(
366 const std::string& k,
const char* default_value,
bool& found)
const 368 if (
nullptr == default_value ) {
369 return find_impl<T>(k,
static_cast<T
>(0), found);
371 return find_impl<T>(k, std::string(default_value), found);
383 T
find(
const std::string& k, T default_value)
const 386 return find_impl<T>(k, default_value, tmp);
399 T
find(
const std::string& k,
const std::string& default_value)
const 402 return find_impl<T>(k, default_value, tmp);
416 std::enable_if_t<std::is_same_v<bool, T>, T>
find(
const std::string& k,
const char* default_value)
const 419 if (
nullptr == default_value ) {
420 return find_impl<T>(k,
static_cast<T
>(0), tmp);
422 return find_impl<T>(k, std::string(default_value), tmp);
433 T
find(
const std::string& k)
const 436 T default_value = T();
437 return find_impl<T>(k, default_value, tmp);
451 std::enable_if_t<!std::is_same_v<bool, T>, T>
find(
const std::string& k,
bool& found)
const 453 T default_value = T();
454 return find_impl<T>(k, default_value, found);
524 std::string value = getString(k, found);
525 if ( !found )
return;
529 if ( value.front() !=
'[' || value.back() !=
']' ) {
530 vec.push_back(convert_value<T>(k, value));
534 value = value.substr(1, value.size() - 2);
537 std::vector<std::string> tokens;
538 getDelimitedTokens(value,
',', tokens);
541 for (
auto& str : tokens ) {
547 for (
auto& val : tokens ) {
548 vec.push_back(convert_value<T>(k, val));
619 std::string value = getString(k, found);
620 if ( !found )
return;
625 if ( value.find(
"set([") == 0 ) {
630 value = value.substr(4, value.length() - 5);
632 value[value.length() - 1] =
'}';
638 if ( value.front() !=
'{' || value.back() !=
'}' ) {
639 set.insert(convert_value<T>(k, value));
643 value = value.substr(1, value.size() - 2);
646 std::vector<std::string> tokens;
647 getDelimitedTokens(value,
',', tokens);
650 for (
auto& str : tokens ) {
656 for (
auto& val : tokens ) {
657 set.insert(convert_value<T>(k, val));
725 template <
class keyT,
class valT>
731 std::string value = getString(k, found);
732 if ( !found )
return;
735 if ( value.front() !=
'{' || value.back() !=
'}' ) {
736 std::string msg =
"Invalid format for parameter to be parsed as a map: " + value;
739 throw std::invalid_argument(msg);
742 value = value.substr(1, value.size() - 2);
745 std::vector<std::string> tokens;
746 getDelimitedTokens(value,
',', tokens);
750 std::vector<std::string> kvpair;
751 for (
auto& x : tokens ) {
753 getDelimitedTokens(x,
':', kvpair);
755 if ( kvpair.size() != 2 ) {
756 std::string msg =
"Invalid format for map key/value pair: " + x;
759 throw std::invalid_argument(msg);
763 cleanToken(kvpair[0]);
764 cleanToken(kvpair[1]);
767 map[convert_value<keyT>(k, kvpair[0])] = convert_value<valT>(k, kvpair[1]);
782 std::string value = getString(k, found);
783 if ( !found )
return false;
785 if ( (value.find(
"[") == std::string::npos) || (value.find(
"]") == std::string::npos) ) {
792 void print_all_params(std::ostream& os,
const std::string& prefix =
"")
const;
796 std::string
toString(
const std::string& prefix =
"")
const;
808 void insert(
const std::string& key,
const std::string& value,
bool overwrite =
true);
823 std::set<std::string>
getKeys()
const;
876 void verifyParam(
const key_type& k)
const;
886 void addSharedParamSet(
const std::string&
set);
900 static void insert_shared(
901 const std::string&
set,
const key_type& key,
const key_type& value,
bool overwrite =
true);
911 static std::map<std::string, std::string> getSharedParamSet(
const std::string& name);
920 static std::vector<std::string> getSharedParamSetNames();
929 std::vector<std::string> getLocalKeys()
const;
939 std::vector<std::string> getSubscribedSharedParamSets()
const;
947 void verifyKey(
const key_type& k)
const;
951 std::map<uint32_t, std::string> my_data;
952 std::vector<std::map<uint32_t, std::string>*> data;
953 std::vector<KeySet_t> allowedKeys;
955 static bool g_verify_enabled;
957 static uint32_t getKey(
const std::string& str);
964 static const std::string& getParamName(uint32_t
id);
967 friend int ::main(
int argc,
char* argv[]);
971 static std::map<std::string, uint32_t> keyMap;
972 static std::vector<std::string> keyMapReverse;
973 static std::recursive_mutex keyLock;
975 static uint32_t nextKeyID;
977 static std::map<std::string, std::map<uint32_t, std::string>> shared_params;
983 #define SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(type) \ 985 type Params::find(const std::string& k, type default_value, bool& found) const; \ 987 type Params::find(const std::string& k, const std::string& default_value, bool& found) const; \ 989 type Params::find(const std::string& k, type default_value) const; \ 991 type Params::find(const std::string& k, const std::string& default_value) const; \ 993 type Params::find(const std::string& k) const; 996 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int32_t)
997 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint32_t)
998 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int64_t)
999 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint64_t)
1000 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
bool)
1001 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
float)
1002 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(
double)
1003 SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(UnitAlgebra)
1008 std::string Params::find<std::string>(
const std::string& k,
const std::string& default_value,
bool &found)
const;
1013 #endif // SST_CORE_PARAMS_H Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:57
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
void print_all_params(std::ostream &os, const std::string &prefix="") const
Print all key/value parameter pairs to specified ostream.
Definition: params.cc:105
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:383
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:399
Outputs configuration data to a specified file path.
Definition: configGraphOutput.h:61
Represents the configuration of a generic component.
Definition: configGraph.h:381
std::enable_if_t<!std::is_same_v< bool, T >, T > 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:451
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:585
Class that represents a PortModule in ConfigGraph.
Definition: configGraph.h:348
static void enableVerify()
Enable, on a global scale, parameter verification.
Definition: params.h:264
bool contains(const key_type &k) const
Search the container for a particular key.
Definition: params.cc:233
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:519
void clear()
Erases all elements, including deleting reference to shared param sets.
Definition: params.cc:86
void pushAllowedKeys(const std::vector< std::string > &keys)
Definition: params.cc:242
std::enable_if_t< std::is_same_v< bool, T >, T > 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:416
Params()
Create a new, empty Params.
Definition: params.cc:58
bool enableVerify(bool enable)
Enable or disable parameter verification on an instance of Params.
Definition: params.h:252
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
std::string toString(const std::string &prefix="") const
Return a string version of all key/value parameter pairs.
Definition: params.cc:147
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:211
std::set< std::string > getKeys() const
Get all the keys contained in the Params object.
Definition: params.cc:198
Definition: threadsafe.h:135
std::enable_if_t< std::is_same_v< bool, T >, T > 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:365
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:614
std::enable_if_t<!std::is_same_v< std::string, T >, T > 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:333
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:243
Parameter store.
Definition: params.h:63
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:252
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:349
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:726
Base class for Model Generation.
Definition: sstmodel.h:29
size_t count(const key_type &k) const
Finds the number of elements with given key.
Definition: params.cc:94
bool empty() const
Returns true if the Params is empty.
Definition: params.cc:53
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:433
size_t size() const
Returns the size of the Params.
Definition: params.cc:47
Params & operator=(const Params &old)
Assignment operator.
Definition: params.cc:75
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:779
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:171
std::string key_type
Definition: params.h:242