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_GRAINS_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_MODELS_GRAINS_INTERFACE_H
22 
23 
24 #include "world_builder/grains.h"
27 
28 
29 namespace WorldBuilder
30 {
35  namespace Features
36  {
37 
38  namespace OceanicPlateModels
39  {
40  namespace Grains
41  {
42  class ObjectFactory;
43 
44  class Interface
45  {
46  public:
50  Interface();
51 
55  virtual
56  ~Interface();
57 
61  static
62  void declare_entries(Parameters &prm,
63  const std::string &parent_name,
64  const std::vector<std::string> &required_entries);
65 
69  virtual
70  void parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) = 0;
71 
72 
76  virtual
78  get_grains(const Point<3> &position,
79  const Objects::NaturalCoordinate &position_in_natural_coordinates,
80  const double depth,
81  const unsigned int composition_number,
83  const double feature_min_depth,
84  const double feature_max_depth) const = 0;
89  static void registerType(const std::string &name,
90  void ( * /*declare_entries*/)(Parameters &, const std::string &),
91  ObjectFactory *factory);
92 
93 
98  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
99 
103  std::string get_name() const
104  {
105  return name;
106  };
107 
108  protected:
113 
114  std::string name;
115 
116 
117 
118  private:
119  static std::map<std::string, ObjectFactory *> &get_factory_map()
120  {
121  static std::map<std::string, ObjectFactory *> factories;
122  return factories;
123  }
124 
125  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
126  {
127  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
128  return declares;
129  }
130 
131  };
132 
133 
138  {
139  public:
140  virtual std::unique_ptr<Interface> create(World *world) = 0;
141  };
142 
148 #define WB_REGISTER_FEATURE_OCEANIC_PLATE_GRAINS_MODEL(classname,name) \
149  class classname##Factory : public ObjectFactory { \
150  public: \
151  classname##Factory() \
152  { \
153  Interface::registerType(#name, classname::declare_entries, this); \
154  } \
155  virtual std::unique_ptr<Interface> create(World *world) override final { \
156  return std::unique_ptr<Interface>(new classname(world)); \
157  } \
158  }; \
159  static classname##Factory global_##classname##Factory;
160 
161  } // namespace Grains
162  } // namespace OceanicPlateModels
163  } // namespace Features
164 } // namespace WorldBuilder
165 
166 #endif
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:42
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:88
virtual WorldBuilder::grains get_grains(const Point< 3 > &position, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const unsigned int composition_number, WorldBuilder::grains grains, const double feature_min_depth, const double feature_max_depth) const =0
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:119
virtual void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates)=0
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:79
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:125