DOpE
parameterreader.h
Go to the documentation of this file.
1 
24 #ifndef PARAMETERREADER_h_
25 #define PARAMETERREADER_h_
26 
27 #include <deal.II/base/parameter_handler.h>
28 
29 using namespace dealii;
30 namespace DOpE
31 {
36 class ParameterReader : public Subscriptor
37  {
38  public:
39  inline ParameterReader();
46  inline void SetSubsection(const std::string subsection);
52  inline void read_parameters(const std::string parameter_file);
57  inline void declare_entry (const std::string &entry,
58  const std::string &default_value,
59  const Patterns::PatternBase &pattern=Patterns::Anything(),
60  const std::string &documentation=std::string());
65  inline double get_double (const std::string &entry_name);
70  inline int get_integer (const std::string &entry_name);
75  inline std::string get_string (const std::string &entry_name);
80  inline bool get_bool (const std::string &entry_name);
81 
82  private:
83  ParameterHandler prm;
84  std::string subsection_;
85  };
86 
87 
88  ParameterReader::ParameterReader()
89  {
90  subsection_ = "";
91  }
92 
93 void ParameterReader::SetSubsection(const std::string subsection)
94  {
95  subsection_ = subsection;
96  }
97 
98 void ParameterReader::declare_entry(const std::string &entry,
99  const std::string &default_value,
100  const Patterns::PatternBase &pattern,
101  const std::string &documentation)
102 {
103  prm.enter_subsection (subsection_);
104  {
105  prm.declare_entry(entry,default_value,pattern,documentation);
106  }
107  prm.leave_subsection();
108 }
109 
110 void ParameterReader::read_parameters (const std::string parameter_file)
111  {
112  prm.read_input (parameter_file);
113  }
114 
115 double ParameterReader::get_double (const std::string &entry_name)
116 {
117  double ret;
118  prm.enter_subsection(subsection_);
119  {
120  ret = prm.get_double(entry_name);
121  }
122  prm.leave_subsection();
123  return ret;
124 }
125 
126 int ParameterReader::get_integer (const std::string &entry_name)
127 {
128  int ret;
129  prm.enter_subsection(subsection_);
130  {
131  ret = prm.get_integer(entry_name);
132  }
133  prm.leave_subsection();
134  return ret;
135 }
136 
137  std::string ParameterReader::get_string (const std::string &entry_name)
138 {
139  std::string ret;
140  prm.enter_subsection(subsection_);
141  {
142  ret = prm.get(entry_name);
143  }
144  prm.leave_subsection();
145  return ret;
146 }
147 
148 bool ParameterReader::get_bool(const std::string &entry_name)
149 {
150  bool ret;
151  prm.enter_subsection(subsection_);
152  {
153  ret = prm.get_bool(entry_name);
154  }
155  prm.leave_subsection();
156  return ret;
157 }
158 
159 }
160 #endif
Definition: parameterreader.h:36