SST  11.0.0
StructuralSimulationToolkit
params.h
1 // Copyright 2009-2021 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2021, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_PARAM_H
13 #define SST_CORE_PARAM_H
14 
15 #include "sst/core/output.h"
16 #include "sst/core/from_string.h"
17 
18 #include <cassert>
19 #include <inttypes.h>
20 #include <iostream>
21 #include <sstream>
22 #include <map>
23 #include <stack>
24 #include <stdlib.h>
25 #include <utility>
26 #include "sst/core/threadsafe.h"
27 
28 #include "sst/core/serialization/serializable.h"
29 #include "sst/core/serialization/serializer.h"
30 
31 int main(int argc, char *argv[]);
32 
33 namespace SST {
34 
35 class ConfigGraph;
36 
37 /**
38  * Parameter store.
39  *
40  * Stores key-value pairs as std::strings and provides
41  * a templated find method for finding values and converting
42  * them to arbitrary types (@see find()).
43  */
45 private:
46  struct KeyCompare : std::binary_function<std::string, std::string, bool>
47  {
48  bool operator()(const std::string& X, const std::string& Y) const
49  {
50  const char *x = X.c_str();
51  const char *y = Y.c_str();
52 
53 #define EAT_VAR(A, B) \
54  do { \
55  if ( *x == '%' && (*(x+1) == '(' || *(x+1) == 'd')) { \
56  /* We need to eat off some tokens */ \
57  ++x; \
58  if ( *x == '(' ) { \
59  do { x++; } while ( *x && *x != ')' ); \
60  x++; /* *x should now == 'd' */ \
61  } \
62  if ( *x != 'd' ) goto NO_VARIABLE; \
63  x++; /* Finish eating the variable */ \
64  /* Now, eat of digits of Y */ \
65  while ( *y && isdigit(*y) ) y++; \
66  } \
67  } while(0)
68 
69  do {
70  EAT_VAR(x, y);
71  EAT_VAR(y, x);
72 NO_VARIABLE:
73  if ( *x == *y ) {
74  if ( '\0' == *x ) return false;
75  x++;
76  y++;
77  } else {
78  if ( *x < *y ) return true;
79  return false;
80  }
81  } while ( *x && *y );
82  if ( !(*x) && (*y) ) return true;
83  return false;
84 
85 #undef EAT_VAR
86  }
87  };
88 
89 
90  /** Private utility function to convert a value to the specified
91  * type and check for errors. Key is passed only in case an error
92  * message needs to be generated.
93  *
94  * Type T must be either a basic numeric type (including bool) ,
95  * a std::string, or a class that has a constructor with a std::string
96  * as its only parameter. This class uses SST::Core::from_string to
97  * do the conversion.
98  * @param k - Parameter name
99  * @throw std::invalid_argument If value in (key, value) can't be
100  * converted to type T, an invalid_argument exception is thrown.
101  */
102  template <class T>
103  inline T convert_value(const std::string& key, const std::string& val) const {
104  try {
105  return SST::Core::from_string<T>(val);
106  }
107  catch ( const std::invalid_argument& e ) {
108  std::string msg = "Params::find(): No conversion for value: key = " + key + ", value = " + val +
109  ". Original error: " + e.what();
110  std::invalid_argument t(msg);
111  throw t;
112  }
113  }
114 
115  /** Private utility function to find a Parameter value in the set,
116  * and return its value as a type T.
117  *
118  * Type T must be either a basic numeric type (including bool) ,
119  * a std::string, or a class that has a constructor with a std::string
120  * as its only parameter. This class uses SST::Core::from_string to
121  * do the conversion.
122  * @param k - Parameter name
123  * @param default_value - Default value to return if parameter isn't found
124  * @param found - set to true if the the parameter was found
125  * @throw std::invalid_argument If value in (key, value) can't be
126  * converted to type T, an invalid_argument exception is thrown.
127  */
128  template <class T>
129  inline T find_impl(const std::string& k, T default_value, bool &found) const {
130  verifyParam(k);
131  // const_iterator i = data.find(getKey(k));
132  const std::string& value = getString(k,found);
133  if ( !found ) {
134  return default_value;
135  }
136  else {
137  return convert_value<T>(k,value);
138  }
139  }
140 
141  /** Find a Parameter value in the set, and return its value as a type T.
142  * Type T must be either a basic numeric type (including bool) ,
143  * a std::string, or a class that has a constructor with a std::string
144  * as its only parameter. This class uses SST::Core::from_string to
145  * do the conversion.
146  * @param k - Parameter name
147  * @param default_value - Default value to return if parameter isn't found,
148  * specified as a string
149  * @param found - set to true if the the parameter was found
150  */
151  template <class T>
152  inline T find_impl(const std::string& k, const std::string& default_value, bool &found) const {
153  verifyParam(k);
154  const std::string& value = getString(k,found);
155  if ( !found ) {
156  try {
157  return SST::Core::from_string<T>(default_value);
158  }
159  catch ( const std::invalid_argument& e ) {
160  std::string msg = "Params::find(): Invalid default value specified: key = " + k + ", value = " + default_value +
161  ". Original error: " + e.what();
162  std::invalid_argument t(msg);
163  throw t;
164  }
165  }
166  else {
167  found = true;
168  try {
169  return SST::Core::from_string<T>(value);
170  }
171  catch ( const std::invalid_argument& e ) {
172  std::string msg = "Params::find(): No conversion for value: key = " + k + ", value = " + value +
173  ". Original error: " + e.what();
174  std::invalid_argument t(msg);
175  throw t;
176  }
177  }
178  }
179 
180  typedef std::map<uint32_t, std::string>::const_iterator const_iterator; /*!< Const Iterator type */
181 
182  const std::string& getString(const std::string& name, bool& found) const;
183 
184  void getArrayTokens(const std::string& value, std::vector<std::string>& tokens) const;
185 
186 public:
187  typedef std::string key_type; /*!< Type of key (string) */
188  typedef std::set<key_type, KeyCompare> KeySet_t; /*!< Type of a set of keys */
189 
190  /**
191  * Enable or disable parameter verification on an instance
192  * of Params. Useful when generating a new set of Params to
193  * pass off to a module.
194  *
195  * @return returns the previous state of the flag
196  */
197  bool enableVerify(bool enable) { bool old = verify_enabled; verify_enabled = enable; return old; }
198 
199  /**
200  * Enable, on a global scale, parameter verification. Used
201  * after construction of the config graph so that warnings are
202  * not generated during construction.
203  */
204  static void enableVerify() { g_verify_enabled = true; };
205 
206  /**
207  * Returns the size of the Params. This will count both local and
208  * global params.
209  *
210  * @return number of key/value pairs in this Params object
211  */
212  size_t size() const;
213  /**
214  * Returns true if the Params is empty. Checks both local and
215  * global param sets.
216  *
217  * @return true if this Params object is empty, false otherwise
218  */
219  bool empty() const;
220 
221 
222  /** Create a new, empty Params */
223  Params();
224 
225  /** Create a copy of a Params object */
226  Params(const Params& old);
227 
228  virtual ~Params() { }
229 
230  /**
231  * @brief Assignment operator.
232  * @param old Param to be copied
233  *
234  * All the elements of old are copied, This will also copy
235  * over any references to global param sets
236  */
237  Params& operator=(const Params& old);
238 
239  /**
240  * Erases all elements, including deleting reference to global
241  * param sets.
242  */
243  void clear();
244 
245 
246  /**
247  * @brief Finds the number of elements with given key.
248  *
249  * The call will check both local and global params, but will
250  * still only report one instance if the given key is found in
251  * both the local and global param sets.
252  *
253  * @param k Key of (key, value) pairs to be located.
254  * @return Number of elements with specified key
255  * (either 1 or 0).
256  *
257  */
258  size_t count(const key_type& k) const;
259 
260  /** Find a Parameter value in the set, and return its value as a type T.
261  * Type T must be either a basic numeric type (including bool) ,
262  * a std::string, or a class that has a constructor with a std::string
263  * as its only parameter. This class uses SST::Core::from_string to
264  * do the conversion.
265  * @param k - Parameter name
266  * @param default_value - Default value to return if parameter isn't found
267  * @param found - set to true if the the parameter was found
268  * @throw std::invalid_argument If value in (key, value) can't be
269  * converted to type T, an invalid_argument exception is thrown.
270  */
271  template <class T>
272  typename std::enable_if<not std::is_same<std::string,T>::value, T>::type
273  find(const std::string& k, T default_value, bool &found) const {
274  return find_impl<T>(k,default_value,found);
275  }
276 
277  /** Find a Parameter value in the set, and return its value as a type T.
278  * Type T must be either a basic numeric type (including bool) ,
279  * a std::string, or a class that has a constructor with a std::string
280  * as its only parameter. This class uses SST::Core::from_string to
281  * do the conversion.
282  * @param k - Parameter name
283  * @param default_value - Default value to return if parameter isn't found,
284  * specified as a string
285  * @param found - set to true if the the parameter was found
286  */
287  template <class T>
288  T find(const std::string& k, const std::string& default_value, bool &found) const {
289  return find_impl<T>(k,default_value,found);
290  }
291 
292  /** Find a Parameter value in the set, and return its value as a type T.
293  * This version of find is only enabled for bool. This
294  * is required because a string literal will be preferentially
295  * cast to a bool rather than a string. This ensures that
296  * find<bool> works correctly for string literals. This class uses
297  * SST::Core::from_string to do the conversion.
298  * @param k - Parameter name
299  * @param default_value - Default value to return if parameter isn't found,
300  * specified as a string literal
301  */
302  template <class T>
303  typename std::enable_if<std::is_same<bool,T>::value, T>::type
304  find(const std::string& k, const char* default_value, bool &found ) const {
305  if ( nullptr == default_value ) {
306  return find_impl<T>(k, static_cast<T>(0), found);
307  }
308  return find_impl<T>(k, std::string(default_value), found);
309  }
310 
311  /** Find a Parameter value in the set, and return its value as a type T.
312  * Type T must be either a basic numeric type (including bool),
313  * a std::string, or a class that has a constructor with a std::string
314  * as its only parameter. This class uses SST::Core::from_string to
315  * do the conversion.
316  * @param k - Parameter name
317  * @param default_value - Default value to return if parameter isn't found
318  */
319  template <class T>
320  T find(const std::string& k, T default_value ) const {
321  bool tmp;
322  return find_impl<T>(k, default_value, tmp);
323  }
324 
325  /** Find a Parameter value in the set, and return its value as a type T.
326  * Type T must be either a basic numeric type (including bool) ,
327  * a std::string, or a class that has a constructor with a std::string
328  * as its only parameter. This class uses SST::Core::from_string to
329  * do the conversion.
330  * @param k - Parameter name
331  * @param default_value - Default value to return if parameter isn't found,
332  * specified as a string
333  */
334  template <class T>
335  T find(const std::string& k, const std::string& default_value ) const {
336  bool tmp;
337  return find_impl<T>(k, default_value, tmp);
338  }
339 
340  /** Find a Parameter value in the set, and return its value as a type T.
341  * This version of find is only enabled for bool. This
342  * is required because a string literal will be preferentially
343  * cast to a bool rather than a string. This ensures that
344  * find<bool> works correctly for string literals.This class uses
345  * SST::Core::from_string to do the conversion.
346  * @param k - Parameter name
347  * @param default_value - Default value to return if parameter isn't found,
348  * specified as a string literal
349  */
350  template <class T>
351  typename std::enable_if<std::is_same<bool,T>::value, T>::type
352  find(const std::string& k, const char* default_value ) const {
353  bool tmp;
354  if ( nullptr == default_value ) {
355  return find_impl<T>(k, static_cast<T>(0), tmp);
356  }
357  return find_impl<T>(k, std::string(default_value), tmp);
358  }
359 
360  /** Find a Parameter value in the set, and return its value as a type T.
361  * Type T must be either a basic numeric type (including bool) ,
362  * a std::string, or a class that has a constructor with a std::string
363  * as its only parameter. This class uses SST::Core::from_string to
364  * do the conversion.
365  * @param k - Parameter name
366  */
367  template <class T>
368  T find(const std::string& k) const {
369  bool tmp;
370  T default_value = T();
371  return find_impl<T>(k, default_value, tmp);
372  }
373 
374  /** Find a Parameter value in the set, and return its value as a
375  * type T. Type T must be either a basic numeric type , a
376  * std::string, or a class that has a constructor with a
377  * std::string as its only parameter. This version of find is not
378  * enabled for bool as it conflicts with find<bool>(string key, bool
379  * default_value). This class uses SST::Core::from_string to do
380  * the conversion.
381  * @param k - Parameter name
382  * @param found - set to true if the the parameter was found
383  */
384  template <class T>
385  typename std::enable_if<not std::is_same<bool, T>::value, T>::type
386  find(const std::string& k, bool &found) const {
387  T default_value = T();
388  return find_impl<T>(k, default_value, found);
389  }
390 
391  /** Find a Parameter value in the set, and return its value as a
392  * vector of T's. The array will be appended to
393  * the end of the vector.
394  *
395  * Type T must be either a basic numeric type (including bool) , a
396  * std::string, or a class that has a constructor with a
397  * std::string as its only parameter. This class uses
398  * SST::Core::from_string to do the conversion. The values in the
399  * array must be enclosed in square brackets ( [] ), and be comma
400  * separated (commas in double or single quotes will not be
401  * considered a delimiter). If there are no square brackets, the
402  * entire string will be considered one value and a single item
403  * will be added to the vector.
404  *
405  * More details about parsing the values out of the string:
406  *
407  * Parses a string representing an array of tokens. It is
408  * tailored to the types strings you get when passing a python
409  * list as the param string. When you call addParam() on a python
410  * list in the input file, it will call the str() function on the
411  * list, which creates a string with the following format:
412  * [item1, item2, item3]
413  *
414  * The format of the items depends on where they came from. The
415  * string for the items are generated by calling the repr()
416  * function on them. For strings, this means they will typically
417  * be enclosed in single quotes. It is possible that they end up
418  * enclosed in double quotes if the string itself contains a
419  * single quote. For strings which contain both single and double
420  * quotes, the repr() will create a single quoted string with all
421  * internal single quotes escaped with '\'. Most other items used
422  * in SST do not enclose the string in quotes, though any string
423  * that contains a comma would need to be enclosed in quotes,
424  * since the comma is the delimiter character used. This is not
425  * done automatically, so if you have something that generates a
426  * commma in the string created by repr(), you may need to create
427  * an array string manually. Also, any string that starts with a
428  * quote character, must end with the same quote character.
429  *
430  * Tokens are generated by splitting the string on commas that are
431  * not within quotes (double or single). All whitespace at the
432  * beginning and end of a token is ignored (unless inside quotes).
433  * Once the tokens are generated, any quoted string will have the
434  * front and back quotes removed. The '\' for any escaped quote
435  * of the same type as the front and back is also removed.
436  *
437  * Examples:
438  *
439  * These will produce the same results:
440  * [1, 2, 3, 4, 5]
441  * ['1', '2', '3', '4', '5']
442  *
443  * Examples of strings using double and/or single quotes:
444  * 'This is "a" test' -> This is "a" test
445  * "This is 'a' test" -> This is 'a' test
446  * 'This "is \'a\'" test' -> This "is 'a'" test
447  * 'This "is \"a\"" test' -> This "is \"a\"" test
448  *
449  * @param k - Parameter name
450  * @param vec - vector to append array items to
451  */
452  template <class T>
453  void find_array(const key_type &k, std::vector<T>& vec) const {
454  verifyParam(k);
455 
456  bool found = false;
457  std::string value = getString(k,found);
458  if ( !found ) return;
459  // If string starts with [ and ends with ], it is considered
460  // an array. Otherwise, it is considered a single
461  // value.
462  if ( value.front() != '[' || value.back() != ']' ) {
463  vec.push_back(convert_value<T>(k,value));
464  return;
465  }
466 
467  value = value.substr(1,value.size()-2);
468 
469  // Get the tokens for the array
470  std::vector<std::string> tokens;
471  getArrayTokens(value,tokens);
472 
473  // Convert each token into the proper type and put in output
474  // vector
475  for ( auto& val : tokens ) {
476  vec.push_back(convert_value<T>(k,val));
477  }
478  }
479 
480  /** Checks to see if the value associated with the given key is
481  * considered to be an array. A value is considered to be an
482  * array if it is enclosed in square brackets ([]). No whitespace
483  * before or after the brackets is allowed.
484  *
485  * @param k - Parameter name
486  * @return true if value is an array as described above, false otherwise.
487  */
488  bool is_value_array(const key_type& k) const {
489  bool found = false;
490  std::string value = getString(k,found);
491  if ( !found ) return false;
492  // String should start with [ and end with ]
493  if( (value.find("[") == std::string::npos) ||
494  (value.find("]") == std::string::npos) ){
495  return false;
496  }
497  return true;
498  }
499 
500  /** Print all key/value parameter pairs to specified ostream */
501  void print_all_params(std::ostream &os, const std::string& prefix = "") const;
502  /** Print all key/value parameter pairs to specified ostream */
503  void print_all_params(Output &out, const std::string& prefix = "") const;
504 
505 
506 
507  /**
508  * Add a key/value pair into the param object.
509  *
510  * @param key key to add to the map
511  *
512  * @param value value to add to the map
513  *
514  * @param overwrite controls whether the key/value pair will
515  * overwrite an existing pair in the set
516  */
517  void insert(const std::string& key, const std::string& value, bool overwrite = true);
518 
519  /**
520  * Add contents of input Params object to current Params object.
521  * This will also add any pointers to global param sets after the
522  * existing pointers to global param sets in this object.
523  *
524  * @param params Params object that should added to current object
525  */
526  void insert(const Params& params);
527 
528 
529  /**
530  Get all the keys contained in the Params object. This will
531  give both local and global params.
532  */
533  std::set<std::string> getKeys() const;
534 
535  /**
536  * Returns a new parameter object with parameters that match the
537  * specified scoped prefix (scopes are separated with "." The
538  * keys will be stripped of the "scope." prefix.
539  *
540  * Function will search both local and global params, but all
541  * params will be copied into the local space of the new Params
542  * object.
543  *
544  * @param scope Scope to search (anything prefixed with "scope."
545  * will be included in the return Params object
546  *
547  * @return New Params object with the found scoped params.
548  */
549  Params get_scoped_params(const std::string& scope) const;
550 
551  /** Returns a new parameter object with parameters that match
552  * the specified prefix.
553  */
554  Params find_prefix_params(const std::string& prefix) const __attribute__ ((deprecated("Params::find_prefix_params() is deprecated and will be removed in SST 12. Please use the new Params::get_scoped_params() function. As of SST 12, only a \".\" will be allowed as a scoping delimiter.")));
555 
556  Params find_scoped_params(const std::string& scope, const char* delims = ".:") const __attribute__ ((deprecated("Params::find_scoped_params() is deprecated and will be removed in SST 12. Please use the new Params::get_scoped_params() function. As of SST 12, only a \".\" will be allowed as a scoping delimiter.")));
557 
558  /**
559  * Search the container for a particular key. This will search
560  * both local and global params.
561  *
562  * @param k Key to search for
563  * @return True if the params contains the key, false otherwise
564  */
565  bool contains(const key_type &k) const;
566 
567  /**
568  * @param keys Set of keys to consider valid to add to the stack
569  * of legal keys
570  */
571  void pushAllowedKeys(const KeySet_t &keys);
572 
573  /**
574  * Removes the most recent set of keys considered allowed
575  */
576  void popAllowedKeys();
577 
578  /**
579  * @param k Key to check for validity
580  * @return True if the key is considered allowed
581  */
582  void verifyParam(const key_type &k) const;
583 
584 
585  /**
586  * Adds a global param set to be looked at in this Params object
587  * if the key isn't found locally. It will search the global sets
588  * in the order they were inserted and return immediately after
589  * finding the key in one of the sets.
590  *
591  * @param set set to add to the search list for this object
592  */
593  void addGlobalParamSet(const std::string& set);
594 
595  /**
596  * Adds a key/value pair to the specified global set
597  *
598  * @param set global set to add the key/value pair to
599  *
600  * @param key key to add to the map
601  *
602  * @param value value to add to the map
603  *
604  * @param overwrite controls whether the key/value pair will
605  * overwrite an existing pair in the set
606  */
607  static void insert_global(const std::string& set, const key_type& key, const key_type& value, bool overwrite = true);
608 
609  void serialize_order(SST::Core::Serialization::serializer &ser) override;
610  ImplementSerializable(SST::Params)
611 
612 
613 
614 private:
615  std::map<uint32_t, std::string> my_data;
616  std::vector<std::map<uint32_t, std::string>*> data;
617  std::vector<KeySet_t> allowedKeys;
618  bool verify_enabled;
619  static bool g_verify_enabled;
620 
621  static uint32_t getKey(const std::string& str);
622  // static uint32_t getKey(const std::string& str);
623 
624  /**
625  * Given a Parameter Key ID, return the Name of the matching parameter
626  * @param id Key ID to look up
627  * @return String name of the parameter
628  */
629  static const std::string& getParamName(uint32_t id);
630 
631 
632  /* Friend main() because it broadcasts the maps */
633  friend int ::main(int argc, char *argv[]);
634 
635  static std::map<std::string, uint32_t> keyMap;
636  static std::vector<std::string> keyMapReverse;
637  static SST::Core::ThreadSafe::Spinlock keyLock;
638  static SST::Core::ThreadSafe::Spinlock globalLock;
639  static uint32_t nextKeyID;
640 
641 
642  static std::map<std::string,std::map<uint32_t,std::string> > global_params;
643 };
644 
645 #if 0
646  class UnitAlgebra;
647 
648  #define SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(type) \
649  template<> \
650  type Params::find(const std::string& k, type default_value, bool &found) const; \
651  template<> \
652  type Params::find(const std::string& k, const std::string& default_value, bool &found) const; \
653  template <> \
654  type Params::find(const std::string& k, type default_value ) const; \
655  template <> \
656  type Params::find(const std::string& k, const std::string& default_value ) const; \
657  template <> \
658  type Params::find(const std::string& k) const;
659 
660 
661  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int32_t)
662  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint32_t)
663  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(int64_t)
664  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(uint64_t)
665  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(bool)
666  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(float)
667  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(double)
668  SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(UnitAlgebra)
669 
670  // std::string has to be special cased because of signature conflicts
671  // SST_PARAMS_DECLARE_TEMPLATE_SPECIALIZATION(std::string)
672  template<>
673  std::string Params::find<std::string>(const std::string& k, const std::string& default_value, bool &found) const;
674 #endif
675 
676 
677 
678 } //namespace SST
679 
680 #endif //SST_CORE_PARAMS_H
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
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&#39;s.
Definition: params.h:453
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:320
Params find_prefix_params(const std::string &prefix) const
Returns a new parameter object with parameters that match the specified prefix.
Definition: params.cc:209
void pushAllowedKeys(const KeySet_t &keys)
Definition: params.cc:259
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:273
bool contains(const key_type &k) const
Search the container for a particular key.
Definition: params.cc:250
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:229
size_t count(const key_type &k) const
Finds the number of elements with given key.
Definition: params.cc:88
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:368
static void enableVerify()
Enable, on a global scale, parameter verification.
Definition: params.h:204
Definition: serializable.h:109
bool empty() const
Returns true if the Params is empty.
Definition: params.cc:47
void clear()
Erases all elements, including deleting reference to global param sets.
Definition: params.cc:79
Params()
Create a new, empty Params.
Definition: params.cc:52
bool enableVerify(bool enable)
Enable or disable parameter verification on an instance of Params.
Definition: params.h:197
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:335
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:386
Definition: threadsafe.h:127
size_t size() const
Returns the size of the Params.
Definition: params.cc:41
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:304
Parameter store.
Definition: params.h:44
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:342
void popAllowedKeys()
Removes the most recent set of keys considered allowed.
Definition: params.cc:265
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:288
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:188
std::string key_type
Definition: params.h:187
void verifyParam(const key_type &k) const
Definition: params.cc:274
void addGlobalParamSet(const std::string &set)
Adds a global param set to be looked at in this Params object if the key isn&#39;t found locally...
Definition: params.cc:335
std::set< std::string > getKeys() const
Get all the keys contained in the Params object.
Definition: params.cc:165
Params & operator=(const Params &old)
Assignment operator.
Definition: params.cc:69
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:140
Performs Unit math in full precision.
Definition: unitAlgebra.h:107
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:352
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:488
void print_all_params(std::ostream &os, const std::string &prefix="") const
Print all key/value parameter pairs to specified ostream.
Definition: params.cc:99