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_COMPOSITION_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_PLUME_MODELS_COMPOSITION_INTERFACE_H
22 
23 
26 
27 namespace WorldBuilder
28 {
29 
34  namespace Features
35  {
36 
37  namespace PlumeModels
38  {
39  namespace Composition
40  {
41  class ObjectFactory;
42 
43  class Interface
44  {
45  public:
49  Interface();
50 
54  virtual
55  ~Interface();
56 
60  static
61  void declare_entries(Parameters &prm,
62  const std::string &parent_name,
63  const std::vector<std::string> &required_entries);
64 
68  virtual
69  void parse_entries(Parameters &prm) = 0;
70 
71 
75  virtual
76  double get_composition(const Point<3> &position,
77  const Objects::NaturalCoordinate &position_in_natural_coordinates,
78  const double depth,
79  const unsigned int composition_number,
80  double composition,
81  const double feature_min_depth,
82  const double feature_max_depth) const = 0;
87  static void registerType(const std::string &name,
88  void ( * /*declare_entries*/)(Parameters &, const std::string &),
89  ObjectFactory *factory);
90 
91 
96  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
97 
101  std::string get_name() const
102  {
103  return name;
104  };
105 
106  protected:
111 
112  std::string name;
113 
114 
115 
116  private:
117  static std::map<std::string, ObjectFactory *> &get_factory_map()
118  {
119  static std::map<std::string, ObjectFactory *> factories;
120  return factories;
121  }
122 
123  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
124  {
125  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
126  return declares;
127  }
128 
129  };
130 
131 
136  {
137  public:
138  virtual std::unique_ptr<Interface> create(World *world) = 0;
139  };
140 
146 #define WB_REGISTER_FEATURE_PLUME_COMPOSITION_MODEL(classname,name) \
147  class classname##Factory : public ObjectFactory { \
148  public: \
149  classname##Factory() \
150  { \
151  Interface::registerType(#name, classname::declare_entries, this); \
152  } \
153  std::unique_ptr<Interface> create(World *world) override final { \
154  return std::unique_ptr<Interface>(new classname(world)); \
155  } \
156  }; \
157  static classname##Factory global_##classname##Factory;
158 
159  } // namespace Composition
160  } // namespace PlumeModels
161  } // namespace Features
162 } // namespace WorldBuilder
163 
164 #endif
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:117
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:48
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:123
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:39
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:57