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_GRAVITY_MODELS_INTERFACE_H
21 #define WORLD_BUILDER_GRAVITY_MODELS_INTERFACE_H
22 
24 
27 
28 
29 namespace WorldBuilder
30 {
31  class World;
32 
33  namespace GravityModel
34  {
35 
36  class ObjectFactory;
37 
41  class Interface
42  {
43  public:
47  Interface();
48 
52  virtual
53  ~Interface();
54 
58  static
59  void declare_entries(Parameters &prm,
60  const std::string &parent_name,
61  const std::vector<std::string> &required_entries);
62 
66  virtual
67  void parse_entries(Parameters &prm) = 0;
68 
72  virtual
73  Point<3> gravity_vector(Point<3> point) const = 0;
74 
78  virtual
79  double gravity_norm(Point<3> point) const = 0;
80 
85  static void registerType(const std::string &name,
86  void ( * /*declare_entries*/)(Parameters &, const std::string &),
87  ObjectFactory *factory);
88 
93  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
94 
95  protected:
100 
101 
102 
103  private:
104  static std::map<std::string, ObjectFactory *> &get_factory_map()
105  {
106  static std::map<std::string, ObjectFactory *> factories;
107  return factories;
108  }
109 
110  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
111  {
112  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
113  return declares;
114  }
115  };
116 
117 
118 
123  {
124  public:
125  virtual std::unique_ptr<Interface> create(World *world) = 0;
126  };
127 
133 #define WB_REGISTER_GRAVITY_MODEL(classname,name) \
134  class classname##Factory : public ObjectFactory { \
135  public: \
136  classname##Factory() \
137  { \
138  Interface::registerType(#name, classname::declare_entries, this); \
139  } \
140  std::unique_ptr<Interface> create(World *world) override final { \
141  return std::unique_ptr<Interface>(new classname(world)); \
142  } \
143  }; \
144  static classname##Factory global_##classname##Factory;
145 
146  } // namespace CoordinateSystems
147 } // namespace WorldBuilder
148 
149 #endif
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:78
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:38
WorldBuilder::World * world
Definition: interface.h:99
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:104
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:110
virtual void parse_entries(Parameters &prm)=0
virtual Point< 3 > gravity_vector(Point< 3 > point) const =0
virtual double gravity_norm(Point< 3 > point) const =0
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:69