World Builder  1.1.0-pre
A geodynamic initial conditions generator
parameters.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2024 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 <map>
24 #include <memory>
25 #include <vector>
26 
27 #include "rapidjson/schema.h"
28 #include "world_builder/point.h"
30 
31 namespace WorldBuilder
32 {
33  namespace Types
34  {
35  class Interface;
36  template<unsigned int dim>
37  class Point;
38  class Double;
39  class String;
40  class Segment;
41  class Array;
42  class Bool;
43  class UnsignedInt;
44  class Int;
45  } // namespace Types
46 
47  namespace Features
48  {
49  class Interface;
50  } // namespace Features
51 
52  namespace CoordinateSystems
53  {
54  class Interface;
55  } // namespace CoordinateSystems
56 
57  namespace GravityModel
58  {
59  class Interface;
60  } // namespace GravityModel
61 
62  class World;
63 
78  class Parameters
79  {
80  public:
85  Parameters(World &world);
86 
90  ~Parameters();
91 
98  void initialize(std::string &filename, bool has_output_dir = false, const std::string &output_dir = "");
99 
108  template<class T>
109  T get(const std::string &name);
110 
115  template<class T>
116  std::vector<T> get_vector(const std::string &name);
117 
118  std::vector<std::vector<double>> get_vector_or_double(const std::string &name);
119 
125  std::pair<std::vector<double>,std::vector<double>>
126  get(const std::string &name,
127  const std::vector<Point<2> > &addition_points = {});
128 
133  std::pair<std::vector<double>,std::vector<double>> get_value_at_array(const std::string &name);
134 
140  template<class T, class A, class B, class C, class D>
141  std::vector<T> get_vector(const std::string &name, std::vector<std::shared_ptr<A> > &, std::vector<std::shared_ptr<B> > &, std::vector<std::shared_ptr<C> > &, std::vector<std::shared_ptr<D> > &);
142 
147  template<class T>
148  std::unique_ptr<T> get_unique_pointer(const std::string &name);
149 
157  template<class T>
158  bool
159  get_unique_pointers(const std::string &name, std::vector<std::unique_ptr<T> > &vector);
160 
168  template<class T>
169  bool
170  get_shared_pointers(const std::string &name, std::vector<std::shared_ptr<T> > & /*vector*/);
171 
181  bool
182  check_entry(const std::string &name) const;
183 
191  void declare_entry(const std::string &name,
192  const Types::Interface &type,
193  const std::string &documentation);
194 
195 
203  void enter_subsection(const std::string &name);
204 
212  void leave_subsection();
213 
222  void
223  declare_model_entries(const std::string &model_group_name,
224  const std::string &parent_name,
225  const std::map<std::string, void ( *)(Parameters &,const std::string &)> &declare_map,
226  const std::vector<std::string> &required_entries = {},
227  const std::vector<std::tuple<std::string,const WorldBuilder::Types::Interface &, std::string> > &extra_declarations = {});
228 
229 
234 
239  const std::string path_separator = ".";
240 
246  std::vector<std::string> path;
247 
248  rapidjson::Document declarations;
249  rapidjson::Document parameters;
250 
251 
252 
253 
260  std::vector<std::unique_ptr<WorldBuilder::Features::Interface> > features;
261 
268  std::unique_ptr<WorldBuilder::CoordinateSystems::Interface> coordinate_system;
269 
276  std::unique_ptr<WorldBuilder::GravityModel::Interface> gravity_model;
277 
283  std::string get_full_json_path(size_t max_size = std::numeric_limits<size_t>::max()) const;
284 
291  std::string get_full_json_schema_path() const;
292 
298  //std::string get_full_path() const;
299 
306  //std::string get_full_path_without_arrays() const;
307 
308  private:
309 
310 
315  size_t path_level;
316 
322  std::string get_relative_path() const;
323 
329  std::string get_relative_path_without_arrays() const;
330  };
331 } // namespace WorldBuilder
332 #endif
rapidjson::Document parameters
Definition: parameters.h:249
std::unique_ptr< WorldBuilder::GravityModel::Interface > gravity_model
Definition: parameters.h:276
std::vector< std::unique_ptr< WorldBuilder::Features::Interface > > features
Definition: parameters.h:260
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
Definition: parameters.h:268
std::vector< std::string > path
Definition: parameters.h:246
rapidjson::Document declarations
Definition: parameters.h:248