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_FEATURES_OCEANIC_PLATE_MODELS_COMPOSITION_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_COMPOSITION_INTERFACE_H
22 
23 
26 
27 
28 namespace WorldBuilder
29 {
30  class World;
31  class Parameters;
32  template <unsigned int dim> class Point;
33 
38  namespace Features
39  {
40 
41  namespace OceanicPlateModels
42  {
43  namespace Composition
44  {
45  class ObjectFactory;
46 
47  class Interface
48  {
49  public:
53  Interface();
54 
58  virtual
59  ~Interface();
60 
64  static
65  void declare_entries(Parameters &prm,
66  const std::string &parent_name,
67  const std::vector<std::string> &required_entries);
68 
72  virtual
73  void parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) = 0;
74 
75 
79  virtual
80  double get_composition(const Point<3> &position,
81  const Objects::NaturalCoordinate &position_in_natural_coordinates,
82  const double depth,
83  const unsigned int composition_number,
84  double composition,
85  const double feature_min_depth,
86  const double feature_max_depth) const = 0;
91  static void registerType(const std::string &name,
92  void ( * /*declare_entries*/)(Parameters &, const std::string &),
93  ObjectFactory *factory);
94 
95 
100  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
101 
105  std::string get_name() const
106  {
107  return name;
108  };
109 
110  protected:
115 
116  std::string name;
117 
118 
119 
120  private:
121  static std::map<std::string, ObjectFactory *> &get_factory_map()
122  {
123  static std::map<std::string, ObjectFactory *> factories;
124  return factories;
125  }
126 
127  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
128  {
129  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
130  return declares;
131  }
132 
133  };
134 
135 
140  {
141  public:
142  virtual std::unique_ptr<Interface> create(World *world) = 0;
143  };
144 
150 #define WB_REGISTER_FEATURE_OCEANIC_PLATE_COMPOSITION_MODEL(classname,name) \
151  class classname##Factory : public ObjectFactory { \
152  public: \
153  classname##Factory() \
154  { \
155  Interface::registerType(#name, classname::declare_entries, this); \
156  } \
157  std::unique_ptr<Interface> create(World *world) override final { \
158  return std::unique_ptr<Interface>(new classname(world)); \
159  } \
160  }; \
161  static classname##Factory global_##classname##Factory;
162 
163  } // namespace Composition
164  } // namespace OceanicPlateModels
165  } // namespace Features
166 } // namespace WorldBuilder
167 
168 #endif
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:127
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:121
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:58
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:49
virtual double get_composition(const Point< 3 > &position, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const unsigned int composition_number, double composition, const double feature_min_depth, const double feature_max_depth) const =0
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:40
virtual void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates)=0