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