SimpleParameterSet.h
Go to the documentation of this file.
1 #ifndef _DBUTILS_SIMPLEPARAMETERSET_H
2 #define _DBUTILS_SIMPLEPARAMETERSET_H
3 
4 #include <boost/lexical_cast.hpp>
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 namespace dbutils {
10 
11 /**
12  * Simple class to set and retrieve key/value pairs.
13  *
14  * This class is somewhat database-specific in its handling of
15  * true/false values.
16  *
17  * @author Kurt Biery
18  * @version $Revision: 1.5.26.1 $ $Date: 2019/09/27 00:07:03 $
19  */
20 
22 
23  public:
24 
25  // *****************
26  // *** Modifiers ***
27  // *****************
28 
29  void put(const std::string& key, const std::string& value)
30  {
31  _paramSet[key] = value;
32  }
33 
34  void clear()
35  {
36  _paramSet.clear();
37  }
38 
39  // *****************
40  // *** Accessors ***
41  // *****************
42 
43  template <class T>
44  bool get(const std::string& key, T& resultValue) const
45  {
46  std::map<std::string, std::string>::const_iterator iter =
47  _paramSet.find(key);
48  if (iter == _paramSet.end()) {return false;}
49 
50  try {
51  resultValue = boost::lexical_cast<T>(iter->second);
52  return true;
53  }
54  catch (...) {
55  // fall through to "false" (failing) return value below
56  }
57  return false;
58  }
59 
60  bool get(const std::string& key, bool& resultValue) const
61  {
62  std::map<std::string, std::string>::const_iterator iter =
63  _paramSet.find(key);
64  if (iter == _paramSet.end()) {return false;}
65 
66  if (iter->second == "t" || iter->second == "1") {
67  resultValue = true;
68  }
69  else {
70  resultValue = false;
71  }
72  return true;
73  }
74 
75  std::vector<std::string> keys() const;
76 
77  std::string toString() const;
78 
79  private:
80 
81  std::map<std::string, std::string> _paramSet;
82 };
83 
84 } // end of namespace dbutils
85 
86 #endif
std::map< std::string, std::string > _paramSet
std::vector< std::string > keys() const
void put(const std::string &key, const std::string &value)
const XML_Char int const XML_Char * value
Definition: expat.h:331
double T
Definition: Xdiff_gwt.C:5
enum BeamMode string