Bridge++  Ver. 2.0.2
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  // print contents.
105  void print(const string& indent = "") const;
106 
107  // obsolete. just for compatibility.
108  void Register_double(const string& key, const double defvalue);
109  void Register_int(const string& key, const int defvalue);
110  void Register_string(const string& key, const string& defvalue);
111  void Register_double_vector(const string& key, const vector<double>& defvalue);
112  void Register_int_vector(const string& key, const vector<int>& defvalue);
113  void Register_string_vector(const string& key, const vector<string>& defvalue);
114  void Register_Parameters(const string& key, const Parameters& defvalue);
115  void Register_Parameters(const string& key, Parameters *const defvalue);
116 
117  private:
118  // scalar
119  map<string, double> m_map_double;
120  map<string, int> m_map_int;
121  map<string, string> m_map_string;
122  // array
123  map<string, vector<double> > m_map_double_vector;
124  map<string, vector<int> > m_map_int_vector;
125  map<string, vector<string> > m_map_string_vector;
126  // map
127  map<string, Parameters> m_map_parameters;
128  // verbose level
130 
131  // utility
132  double convert_to_double(const string&) const;
133  vector<double> convert_to_double(const vector<string>&) const;
134 
135  int convert_to_int(const string&) const;
136  vector<int> convert_to_int(const vector<string>&) const;
137 
138  bool convert_to_bool(const string&) const;
139  bool convert_to_bool(int) const;
140 
141  public:
142  // for debug
143  void dump(const string& indent = "") const;
144 
145  // utility
146  template<typename T>
147  static
148  string to_string(const vector<T>& v)
149  {
150  std::stringstream ss;
151 
152  ss << "[";
153  for (size_t i = 0, n = v.size(); i < n; ++i) {
154  if (i > 0) ss << ", ";
155  ss << v[i];
156  }
157  ss << "]";
158 
159  return ss.str();
160  }
161 };
162 #endif
Parameters::set_bool
void set_bool(const string &key, const bool value)
Definition: parameters.cpp:30
Parameters::find_string
bool find_string(const string &key) const
Definition: parameters.cpp:507
bridgeIO.h
Parameters::set_VerboseLevel
void set_VerboseLevel(const Bridge::VerboseLevel value)
Definition: parameters.cpp:54
Parameters::set_string
void set_string(const string &key, const string &value)
Definition: parameters.cpp:39
Parameters::~Parameters
virtual ~Parameters()
Definition: parameters.h:53
Parameters
Class for parameters.
Definition: parameters.h:46
Parameters::Register_int_vector
void Register_int_vector(const string &key, const vector< int > &defvalue)
Definition: parameters.cpp:481
Parameters::set_double
void set_double(const string &key, const double value)
Definition: parameters.cpp:33
Parameters::m_map_int
map< string, int > m_map_int
Definition: parameters.h:120
Parameters::find_bool
bool find_bool(const string &key) const
Definition: parameters.cpp:510
Parameters::m_map_double_vector
map< string, vector< double > > m_map_double_vector
Definition: parameters.h:123
Parameters::get_int
int get_int(const string &key) const
Definition: parameters.cpp:192
Parameters::find_unsigned_long
bool find_unsigned_long(const string &key) const
Definition: parameters.cpp:500
Parameters::find_Parameters
bool find_Parameters(const string &key) const
Definition: parameters.cpp:522
Parameters::m_map_string
map< string, string > m_map_string
Definition: parameters.h:121
Parameters::m_map_parameters
map< string, Parameters > m_map_parameters
Definition: parameters.h:127
Parameters::Register_string_vector
void Register_string_vector(const string &key, const vector< string > &defvalue)
Definition: parameters.cpp:484
Parameters::m_map_int_vector
map< string, vector< int > > m_map_int_vector
Definition: parameters.h:124
Parameters::m_map_double
map< string, double > m_map_double
Definition: parameters.h:119
Parameters::set_double_vector
void set_double_vector(const string &key, const vector< double > &value)
Definition: parameters.cpp:42
parameterCheck.h
Parameters::Register_string
void Register_string(const string &key, const string &defvalue)
Definition: parameters.cpp:475
Parameters::find_int_vector
bool find_int_vector(const string &key) const
Definition: parameters.cpp:516
Parameters::find_string_vector
bool find_string_vector(const string &key) const
Definition: parameters.cpp:519
Parameters::find_double_vector
bool find_double_vector(const string &key) const
Definition: parameters.cpp:513
Parameters::fetch_bool
int fetch_bool(const string &key, bool &value) const
Definition: parameters.cpp:391
Parameters::get_int_vector
vector< int > get_int_vector(const string &key) const
Definition: parameters.cpp:267
Parameters::to_string
static string to_string(const vector< T > &v)
Definition: parameters.h:148
Parameters::m_map_string_vector
map< string, vector< string > > m_map_string_vector
Definition: parameters.h:125
Parameters::print
void print(const string &indent="") const
Definition: parameters.cpp:541
Parameters::set_string_vector
void set_string_vector(const string &key, const vector< string > &value)
Definition: parameters.cpp:48
Parameters::fetch_string_vector
int fetch_string_vector(const string &key, vector< string > &value) const
Definition: parameters.cpp:448
Parameters::Parameters
Parameters()
Definition: parameters.cpp:22
Parameters::find_double
bool find_double(const string &key) const
Definition: parameters.cpp:494
Parameters::fetch_int_vector
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
Parameters::convert_to_bool
bool convert_to_bool(const string &) const
Definition: parameters.cpp:148
Parameters::dump
void dump(const string &indent="") const
Definition: parameters.cpp:583
Parameters::convert_to_int
int convert_to_int(const string &) const
Definition: parameters.cpp:119
Parameters::set_Parameters
void set_Parameters(const string &key, const Parameters &value)
Definition: parameters.cpp:51
Parameters::get_bool
bool get_bool(const string &key) const
Definition: parameters.cpp:233
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Parameters::class_name
static const std::string class_name
Definition: parameters.h:49
Parameters::set_int_vector
void set_int_vector(const string &key, const vector< int > &value)
Definition: parameters.cpp:45
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
Parameters::Register_int
void Register_int(const string &key, const int defvalue)
Definition: parameters.cpp:472
Parameters::set_int
void set_int(const string &key, const int value)
Definition: parameters.cpp:36
Parameters::convert_to_double
double convert_to_double(const string &) const
Definition: parameters.cpp:66
Parameters::fetch_string
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Parameters::get_VerboseLevel
Bridge::VerboseLevel get_VerboseLevel() const
Definition: parameters.cpp:320
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Parameters::get_Parameters
Parameters get_Parameters(const string &key) const
Definition: parameters.cpp:296
communicator.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Parameters::find_int
bool find_int(const string &key) const
Definition: parameters.cpp:497
Parameters::get_double_vector
vector< double > get_double_vector(const string &key) const
Definition: parameters.cpp:250
Parameters::fetch_double_vector
int fetch_double_vector(const string &key, vector< double > &value) const
Definition: parameters.cpp:410
Parameters::get_string_vector
vector< string > get_string_vector(const string &key) const
Definition: parameters.cpp:284
Parameters::fetch_unsigned_long
int fetch_unsigned_long(const string &key, unsigned long &value) const
Definition: parameters.cpp:365
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Parameters::lookup
Parameters & lookup(const string &key)
Definition: parameters.h:80
Parameters::Register_double_vector
void Register_double_vector(const string &key, const vector< double > &defvalue)
Definition: parameters.cpp:478
Parameters::Register_Parameters
void Register_Parameters(const string &key, const Parameters &defvalue)
Definition: parameters.cpp:487
Parameters::Register_double
void Register_double(const string &key, const double defvalue)
Definition: parameters.cpp:469
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Parameters::m_vlevel
Bridge::VerboseLevel m_vlevel
Definition: parameters.h:129
Parameters::fetch_VerboseLevel
int fetch_VerboseLevel(Bridge::VerboseLevel &value) const
Definition: parameters.cpp:461