Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parameters.h
Go to the documentation of this file.
1 
14 #ifndef PARAMETERS_INCLUDED
15 #define PARAMETERS_INCLUDED
16 
17 #include <string>
18 #include <map>
19 #include <vector>
20 #include <sstream>
21 
23 #include "parameterCheck.h"
24 
25 #include "IO/bridgeIO.h"
26 using Bridge::vout;
27 
28 using std::string;
29 using std::map;
30 using std::vector;
31 
33 
47 {
48  public:
49  static const std::string class_name;
50 
51  public:
52  Parameters();
53  virtual ~Parameters() {}
54 
55  void set_bool(const string& key, const bool value);
56  void set_double(const string& key, const double value);
57  void set_int(const string& key, const int value);
58  void set_string(const string& key, const string& value);
59  void set_double_vector(const string& key, const vector<double>& value);
60  void set_int_vector(const string& key, const vector<int>& value);
61  void set_string_vector(const string& key, const vector<string>& value);
62  void set_Parameters(const string& key, const Parameters& value);
63  void set_VerboseLevel(const Bridge::VerboseLevel value);
64 
65  double get_double(const string& key) const;
66  int get_int(const string& key) const;
67  unsigned long get_unsigned_long(const string& key) const;
68  string get_string(const string& key) const;
69  bool get_bool(const string& key) const;
70 
71  vector<double> get_double_vector(const string& key) const;
72  vector<int> get_int_vector(const string& key) const;
73  vector<string> get_string_vector(const string& key) const;
74 
75  Parameters get_Parameters(const string& key) const;
76  Parameters& get_Parameters(const string& key);
78 
79  Parameters lookup(const string& key) const { return get_Parameters(key); }
80  Parameters& lookup(const string& key) { return get_Parameters(key); }
81 
82  int fetch_double(const string& key, double& value) const;
83  int fetch_int(const string& key, int& value) const;
84  int fetch_unsigned_long(const string& key, unsigned long& value) const;
85  int fetch_string(const string& key, string& value) const;
86  int fetch_bool(const string& key, bool& value) const;
87  int fetch_double_vector(const string& key, vector<double>& value) const;
88  int fetch_int_vector(const string& key, vector<int>& value) const;
89  int fetch_string_vector(const string& key, vector<string>& value) const;
90  int fetch_VerboseLevel(Bridge::VerboseLevel& value) const;
91 
92  bool find_double(const string& key) const;
93  bool find_int(const string& key) const;
94  bool find_unsigned_long(const string& key) const;
95  bool find_string(const string& key) const;
96  bool find_bool(const string& key) const;
97  bool find_double_vector(const string& key) const;
98  bool find_int_vector(const string& key) const;
99  bool find_string_vector(const string& key) const;
100  bool find_Parameters(const string& key) const;
101 
102  bool is_set(const string& key) const;
103 
104  // obsolete. just for compatibility.
105  void Register_double(const string& key, const double defvalue);
106  void Register_int(const string& key, const int defvalue);
107  void Register_string(const string& key, const string& defvalue);
108  void Register_double_vector(const string& key, const vector<double>& defvalue);
109  void Register_int_vector(const string& key, const vector<int>& defvalue);
110  void Register_string_vector(const string& key, const vector<string>& defvalue);
111  void Register_Parameters(const string& key, const Parameters& defvalue);
112  void Register_Parameters(const string& key, Parameters *const defvalue);
113  void Register_Parameters(const string& key, const unique_ptr<Parameters>& defvalue);
114 
115  private:
116  // scalar
117  map<string, double> m_map_double;
118  map<string, int> m_map_int;
119  map<string, string> m_map_string;
120  // array
121  map<string, vector<double> > m_map_double_vector;
122  map<string, vector<int> > m_map_int_vector;
123  map<string, vector<string> > m_map_string_vector;
124  // map
125  map<string, Parameters> m_map_parameters;
126  // verbose level
128 
129  // utility
130  double convert_to_double(const string&) const;
131  vector<double> convert_to_double(const vector<string>&) const;
132 
133  int convert_to_int(const string&) const;
134  vector<int> convert_to_int(const vector<string>&) const;
135 
136  bool convert_to_bool(const string&) const;
137  bool convert_to_bool(int) const;
138 
139  public:
140  void print(const string& indent = "") const;
141 
142  // utility
143  template<typename T>
144  static
145  string to_string(const vector<T>& v)
146  {
147  std::stringstream ss;
148 
149  ss << "[";
150  for (size_t i = 0, n = v.size(); i < n; ++i) {
151  if (i > 0) ss << ", ";
152  ss << v[i];
153  }
154  ss << "]";
155 
156  return ss.str();
157  }
158 };
159 #endif
map< string, vector< string > > m_map_string_vector
Definition: parameters.h:123
void set_Parameters(const string &key, const Parameters &value)
Definition: parameters.cpp:51
BridgeIO vout
Definition: bridgeIO.cpp:503
Parameters get_Parameters(const string &key) const
Definition: parameters.cpp:296
int fetch_bool(const string &key, bool &value) const
Definition: parameters.cpp:391
int fetch_double_vector(const string &key, vector< double > &value) const
Definition: parameters.cpp:410
int convert_to_int(const string &) const
Definition: parameters.cpp:119
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
static const std::string class_name
Definition: parameters.h:49
bool get_bool(const string &key) const
Definition: parameters.cpp:233
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
bool find_bool(const string &key) const
Definition: parameters.cpp:513
bool find_unsigned_long(const string &key) const
Definition: parameters.cpp:503
void Register_int(const string &key, const int defvalue)
Definition: parameters.cpp:472
bool find_int_vector(const string &key) const
Definition: parameters.cpp:519
int get_int(const string &key) const
Definition: parameters.cpp:192
double convert_to_double(const string &) const
Definition: parameters.cpp:66
void Register_double_vector(const string &key, const vector< double > &defvalue)
Definition: parameters.cpp:478
Class for parameters.
Definition: parameters.h:46
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
void Register_Parameters(const string &key, const Parameters &defvalue)
Definition: parameters.cpp:487
Parameters lookup(const string &key) const
Definition: parameters.h:79
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
Bridge::VerboseLevel m_vlevel
Definition: parameters.h:127
void set_bool(const string &key, const bool value)
Definition: parameters.cpp:30
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
Parameters & lookup(const string &key)
Definition: parameters.h:80
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
void set_VerboseLevel(const Bridge::VerboseLevel value)
Definition: parameters.cpp:54
bool find_Parameters(const string &key) const
Definition: parameters.cpp:525
void print(const string &indent="") const
Definition: parameters.cpp:544
Bridge::VerboseLevel get_VerboseLevel() const
Definition: parameters.cpp:320
void Register_double(const string &key, const double defvalue)
Definition: parameters.cpp:469
void Register_int_vector(const string &key, const vector< int > &defvalue)
Definition: parameters.cpp:481
map< string, Parameters > m_map_parameters
Definition: parameters.h:125
bool is_set(const string &key) const
Definition: parameters.cpp:528
bool find_double(const string &key) const
Definition: parameters.cpp:497
bool find_int(const string &key) const
Definition: parameters.cpp:500
void set_double_vector(const string &key, const vector< double > &value)
Definition: parameters.cpp:42
void Register_string(const string &key, const string &defvalue)
Definition: parameters.cpp:475
map< string, double > m_map_double
Definition: parameters.h:117
virtual ~Parameters()
Definition: parameters.h:53
map< string, string > m_map_string
Definition: parameters.h:119
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
void Register_string_vector(const string &key, const vector< string > &defvalue)
Definition: parameters.cpp:484
int fetch_string_vector(const string &key, vector< string > &value) const
Definition: parameters.cpp:448
VerboseLevel
Definition: bridgeIO.h:42
map< string, vector< double > > m_map_double_vector
Definition: parameters.h:121
vector< double > get_double_vector(const string &key) const
Definition: parameters.cpp:250
vector< string > get_string_vector(const string &key) const
Definition: parameters.cpp:284
bool find_string(const string &key) const
Definition: parameters.cpp:510
map< string, int > m_map_int
Definition: parameters.h:118
map< string, vector< int > > m_map_int_vector
Definition: parameters.h:122
int fetch_unsigned_long(const string &key, unsigned long &value) const
Definition: parameters.cpp:365
string get_string(const string &key) const
Definition: parameters.cpp:221
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
bool convert_to_bool(const string &) const
Definition: parameters.cpp:148
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
bool find_double_vector(const string &key) const
Definition: parameters.cpp:516
bool find_string_vector(const string &key) const
Definition: parameters.cpp:522
int fetch_VerboseLevel(Bridge::VerboseLevel &value) const
Definition: parameters.cpp:461
void set_string_vector(const string &key, const vector< string > &value)
Definition: parameters.cpp:48
static string to_string(const vector< T > &v)
Definition: parameters.h:145