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_PLUME_MODELS_GRAINS_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_PLUME_MODELS_GRAINS_INTERFACE_H
22 
23 
24 #include "world_builder/grains.h"
27 
28 
29 namespace WorldBuilder
30 {
31  class World;
32  class Parameters;
33  template <unsigned int dim> class Point;
34 
39  namespace Features
40  {
41 
42  namespace PlumeModels
43  {
44  namespace Grains
45  {
46  class ObjectFactory;
47 
48  class Interface
49  {
50  public:
54  Interface();
55 
59  virtual
60  ~Interface();
61 
65  static
66  void declare_entries(Parameters &prm,
67  const std::string &parent_name,
68  const std::vector<std::string> &required_entries);
69 
73  virtual
74  void parse_entries(Parameters &prm) = 0;
75 
76 
80  virtual
82  get_grains(const Point<3> &position,
83  const Objects::NaturalCoordinate &position_in_natural_coordinates,
84  const double depth,
85  const unsigned int composition_number,
87  const double feature_min_depth,
88  const double feature_max_depth) const = 0;
93  static void registerType(const std::string &name,
94  void ( * /*declare_entries*/)(Parameters &, const std::string &),
95  ObjectFactory *factory);
96 
97 
102  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
103 
107  std::string get_name() const
108  {
109  return name;
110  };
111 
112  protected:
117 
118  std::string name;
119 
120 
121 
122  private:
123  static std::map<std::string, ObjectFactory *> &get_factory_map()
124  {
125  static std::map<std::string, ObjectFactory *> factories;
126  return factories;
127  }
128 
129  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
130  {
131  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
132  return declares;
133  }
134 
135  };
136 
137 
142  {
143  public:
144  virtual std::unique_ptr<Interface> create(World *world) = 0;
145  };
146 
152 #define WB_REGISTER_FEATURE_PLUME_GRAINS_MODEL(classname,name) \
153  class classname##Factory : public ObjectFactory { \
154  public: \
155  classname##Factory() \
156  { \
157  Interface::registerType(#name, classname::declare_entries, this); \
158  } \
159  virtual std::unique_ptr<Interface> create(World *world) override final { \
160  return std::unique_ptr<Interface>(new classname(world)); \
161  } \
162  }; \
163  static classname##Factory global_##classname##Factory;
164 
165  } // namespace Grains
166  } // namespace PlumeModels
167  } // namespace Features
168 } // namespace WorldBuilder
169 
170 #endif
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 void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:40
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:123
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
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:129