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_FAULT_MODELS_VELOCITY_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_FAULT_MODELS_VELOCITY_INTERFACE_H
22 
26 
27 #include <map>
28 #include <vector>
29 
30 namespace WorldBuilder
31 {
32  class World;
33  class Parameters;
34  template <unsigned int dim> class Point;
35 
40  namespace Features
41  {
42  using namespace FeatureUtilities;
43  namespace FaultModels
44  {
45  namespace Velocity
46  {
47  class ObjectFactory;
48 
49  class Interface
50  {
51  public:
55  Interface();
56 
60  virtual
61  ~Interface();
62 
66  static
67  void declare_entries(Parameters &prm,
68  const std::string &parent_name,
69  const std::vector<std::string> &required_entries);
70 
74  virtual
75  void parse_entries(Parameters &prm) = 0;
76 
77 
81  virtual
82  std::array<double,3> get_velocity(const Point<3> &position,
83  const double depth,
84  const double gravity,
85  std::array<double,3> velocity,
86  const double feature_min_depth,
87  const double feature_max_depth,
89  const AdditionalParameters &additional_parameters) const = 0;
94  static void registerType(const std::string &name,
95  void ( * /*declare_entries*/)(Parameters &, const std::string &),
96  ObjectFactory *factory);
97 
98 
103  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
104 
108  std::string get_name() const
109  {
110  return name;
111  };
112 
113  protected:
118 
122  std::string name;
123 
124  private:
125  static std::map<std::string, ObjectFactory *> &get_factory_map()
126  {
127  static std::map<std::string, ObjectFactory *> factories;
128  return factories;
129  }
130 
131  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
132  {
133  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
134  return declares;
135  }
136 
137  };
138 
139 
144  {
145  public:
146  virtual std::unique_ptr<Interface> create(World *world) = 0;
147  };
148 
154 #define WB_REGISTER_FEATURE_FAULT_VELOCITY_MODEL(classname,name) \
155  class classname##Factory : public ObjectFactory { \
156  public: \
157  classname##Factory() \
158  { \
159  Interface::registerType(#name, classname::declare_entries, this); \
160  } \
161  std::unique_ptr<Interface> create(World *world) override final { \
162  return std::unique_ptr<Interface>(new classname(world)); \
163  } \
164  }; \
165  static classname##Factory global_##classname##Factory;
166 
167  } // namespace Velocity
168  } // namespace FaultModels
169  } // namespace Features
170 } // namespace WorldBuilder
171 
172 #endif
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:131
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:125