World Builder  0.1.0-pre
A geodyanmic initial conditions generator
parameters.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef _world_builder_parameters_h
21 #define _world_builder_parameters_h
22 
23 #include <string>
24 #include <vector>
25 #include <unordered_map>
26 
27 #include <boost/property_tree/ptree.hpp>
28 
36 
37 
38 
39 using boost::property_tree::ptree;
40 
41 namespace WorldBuilder
42 {
43 
44  namespace Features
45  {
46  class Interface;
47  }
48 
49  namespace CoordinateSystems
50  {
51  class Interface;
52  }
53 
54  class World;
55 
70  class Parameters
71  {
72  public:
78  Parameters(std::string &filename, World &);
79 
83  ~Parameters();
84 
104  bool load_entry(const std::string &name, const bool required, const Types::Interface &type);
105 
118  bool set_entry(const std::string &name, const Types::Interface &type);
119 
127  void enter_subsection(const std::string name);
128 
136  void leave_subsection();
137 
144  unsigned int get_unsigned_int(const std::string &name) const;
145 
152  double get_double(const std::string &name) const;
153 
160  std::string get_string(const std::string &name) const;
161 
162  // get_array(const std::string& name);
163 
171  template<int dim>
172  Point<dim> get_point(const std::string &name) const;
173 
174  // TODO:
175  //template<class T>
176  //T get(const std::string &name);
177 
178 
187  const Types::Array &get_array(const std::string &name) const;
188 
196  template<class T>
197  const std::vector<T *> get_array(const std::string &name) const;
198 
203 
208  const std::string path_seperator = ".";
209 
215  std::vector<std::string> path;
216 
217 
221  ptree tree;
222 
228  ptree *local_tree;
229 
236  std::unordered_map<std::string,unsigned int> string_to_type_map;
237 
246  std::vector<Types::UnsignedInt> vector_unsigned_int;
247 
256  std::vector<Types::Double> vector_double;
257 
266  std::vector<Types::String> vector_string;
267 
276  std::vector<Types::Array> vector_array;
277 
284  std::vector<Types::List> vector_list;
285 
294  std::vector<Types::Point<2> > vector_point_2d;
295 
304  std::vector<Types::Point<3> > vector_point_3d;
305 
306 
313  std::vector<std::unique_ptr<WorldBuilder::Features::Interface> > features;
314 
321  std::unique_ptr<WorldBuilder::CoordinateSystems::Interface> coordinate_system;
322 
328  std::string get_full_path() const;
329 
336  std::string get_full_path_without_arrays() const;
337 
338  private:
344  bool load_entry(const std::string &name, const bool required, const Types::Interface &type, unsigned int &location);
345 
351  bool set_entry(const std::string &name, const Types::Interface &type, unsigned int &location);
352 
353 
358  unsigned int path_level;
359 
365  std::string get_relative_path() const;
366 
372  std::string get_relative_path_without_arrays() const;
373  };
374 }
375 #endif
std::vector< Types::Array > vector_array
Definition: parameters.h:276
std::vector< Types::List > vector_list
Definition: parameters.h:284
std::vector< Types::Double > vector_double
Definition: parameters.h:256
std::vector< Types::String > vector_string
Definition: parameters.h:266
std::unordered_map< std::string, unsigned int > string_to_type_map
Definition: parameters.h:236
std::vector< Types::Point< 2 > > vector_point_2d
Definition: parameters.h:294
std::vector< std::unique_ptr< WorldBuilder::Features::Interface > > features
Definition: parameters.h:313
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
Definition: parameters.h:321
std::vector< std::string > path
Definition: parameters.h:215
std::vector< Types::Point< 3 > > vector_point_3d
Definition: parameters.h:304
std::vector< Types::UnsignedInt > vector_unsigned_int
Definition: parameters.h:246