World Builder  1.1.0-pre
A geodynamic initial conditions generator
interface.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_COORDINATE_SYSTEMS_INTERFACE_H
21 #define WORLD_BUILDER_COORDINATE_SYSTEMS_INTERFACE_H
22 
24 
28 
29 
30 namespace WorldBuilder
31 {
32  class World;
33 
34  namespace CoordinateSystems
35  {
36 
37  class ObjectFactory;
38 
42  class Interface
43  {
44  public:
48  Interface();
49 
53  virtual
54  ~Interface();
55 
59  static
60  void declare_entries(Parameters &prm,
61  const std::string &parent_name,
62  const std::vector<std::string> &required_entries);
63 
67  virtual
68  void parse_entries(Parameters &prm) = 0;
69 
73  virtual
75 
81  virtual
82  DepthMethod depth_method() const = 0;
83 
91  virtual
92  std::array<double,3> cartesian_to_natural_coordinates(const std::array<double,3> &position) const = 0;
93 
99  virtual
100  std::array<double,3> natural_to_cartesian_coordinates(const std::array<double,3> &position) const = 0;
101 
106  virtual
107  double distance_between_points_at_same_depth(const Point<3> &point_1, const Point<3> &point_2) const = 0;
108 
113  virtual
114  double max_model_depth() const = 0;
115 
120  static void registerType(const std::string &name,
121  void ( * /*declare_entries*/)(Parameters &, const std::string &),
122  ObjectFactory *factory);
123 
128  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
129 
130  protected:
135 
136 
137 
138  private:
139  static std::map<std::string, ObjectFactory *> &get_factory_map()
140  {
141  static std::map<std::string, ObjectFactory *> factories;
142  return factories;
143  }
144 
145  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
146  {
147  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
148  return declares;
149  }
150  };
151 
152 
153 
158  {
159  public:
160  virtual std::unique_ptr<Interface> create(World *world) = 0;
161  };
162 
168 #define WB_REGISTER_COORDINATE_SYSTEM(classname,name) \
169  class classname##Factory : public ObjectFactory { \
170  public: \
171  classname##Factory() \
172  { \
173  Interface::registerType(#name, classname::declare_entries, this); \
174  } \
175  std::unique_ptr<Interface> create(World *world) override final { \
176  return std::unique_ptr<Interface>(new classname(world)); \
177  } \
178  }; \
179  static classname##Factory global_##classname##Factory;
180 
181  } // namespace CoordinateSystems
182 } // namespace WorldBuilder
183 
184 #endif
virtual DepthMethod depth_method() const =0
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:139
virtual CoordinateSystem natural_coordinate_system() const =0
virtual double max_model_depth() const =0
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:79
virtual std::array< double, 3 > cartesian_to_natural_coordinates(const std::array< double, 3 > &position) const =0
virtual double distance_between_points_at_same_depth(const Point< 3 > &point_1, const Point< 3 > &point_2) const =0
virtual void parse_entries(Parameters &prm)=0
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:145
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:39
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:70
virtual std::array< double, 3 > natural_to_cartesian_coordinates(const std::array< double, 3 > &position) const =0