Bridge++  Ver. 1.1.x
 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 using std::string;
19 
20 #include <map>
21 #include <valarray>
22 
23 #include "commonParameters.h"
24 #include "communicator.h"
25 #include "checker.h"
26 
27 #include "bridgeIO.h"
28 using Bridge::vout;
29 
31 
41 {
42  private:
43 
44  template<typename T>
45  struct Item
46  {
47  Item(const T& value)
48  : m_value(value), m_flag_set(EXIT_FAILURE) {}
49  //: m_value(value), m_flag_set(false) {}
50 
52  // bool m_flag_set;
54 
55  const T& value() const { return m_value; }
56  // bool is_set() const { return m_flag_set; }
57  int is_set() const { return m_flag_set; }
58 
59  template<typename U>
60  void put(const std::valarray<U>& value)
61  {
62  m_value.resize(value.size());
63  m_value = value;
64  // m_flag_set = true;
65  m_flag_set = EXIT_SUCCESS;
66  }
67 
68  template<typename U>
69  void put(const U& value)
70  {
71  m_value = value;
72  // m_flag_set = true;
73  m_flag_set = EXIT_SUCCESS;
74  }
75  };
76 
77  std::map<string, Item<double> > m_map_double;
78  std::map<string, Item<int> > m_map_int;
79  std::map<string, Item<std::valarray<double> > > m_map_double_vector;
80  std::map<string, Item<std::valarray<int> > > m_map_int_vector;
81  std::map<string, Item<string> > m_map_string;
82  std::map<string, Item<Parameters *> > m_map_Parameters;
84 
85  public:
86 
87  Parameters();
88 
89  virtual ~Parameters() {}
90 
91  void set_double(const string& key, const double value);
92  void set_int(const string& key, const int value);
93  void set_double_vector(const string& key, const std::valarray<double>& value);
94  void set_int_vector(const string& key, const std::valarray<int>& value);
95  void set_string(const string& key, const string& value);
96  void set_Parameters(const string& key, Parameters *const value);
98 
99  double get_double(const string& key) const;
100  int get_int(const string& key) const;
101 
102  std::valarray<double> get_double_vector(const string& key) const;
103 
104  std::valarray<int> get_int_vector(const string& key) const;
105  string get_string(const string& key) const;
106  Parameters *get_Parameters(const string& key) const;
108 
109  // bool fetch_double( const string& key, double& val) const;
110  int fetch_double(const string& key, double& val) const;
111  int fetch_int(const string& key, int& val) const;
112  int fetch_double_vector(const string& key, std::valarray<double>& val) const;
113  int fetch_int_vector(const string& key, std::valarray<int>& val) const;
114  int fetch_string(const string& key, string& val) const;
116 
117  void Register_double(const string&, const double);
118  void Register_int(const string&, const int);
119  void Register_double_vector(const string&, const std::valarray<double>&);
120  void Register_int_vector(const string&, const std::valarray<int>&);
121  void Register_string(const string&, const string&);
122  void Register_Parameters(const string&, Parameters *const);
123 
124  bool find_double(const string&) const;
125  bool find_int(const string&) const;
126  bool find_double_vector(const string&) const;
127  bool find_int_vector(const string&) const;
128  bool find_string(const string&) const;
129  bool find_Parameters(const string&) const;
130 
131 #ifdef DEBUG
132  void dump(const string& indent = "") const;
133 #endif
134 };
135 #endif