Phoxonics  1.0
Object Oriented FDTD Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GridFactory.hpp
Go to the documentation of this file.
1 /*
2  * GridFacroty.hpp
3  *
4  * Created on: Oct 18, 2014
5  * Author: nano
6  */
7 
8 #ifndef GRIDFACTORY_HPP_
9 #define GRIDFACTORY_HPP_
10 
11 #include "GridBase.hpp"
12 #include "../config/SimulationConfig.hpp"
13 #include "../common/FactoryBase.hpp"
14 #include "../../../common/common.hpp"
15 
16 #include <memory>
17 #include <string>
18 #include <map>
19 #include <functional>
20 
21 namespace phoxonics {
22 namespace core {
23 
24 // The factory - implements singleton pattern!
25 class GridFactory : public FactoryBase {
26 public:
27  virtual ~GridFactory();
28 
29  // Get the single instance of the factory
30  static GridFactory* instance();
31 
32  // register a factory function to create an instance of class_name
33  void register_factory_function(std::string class_name,
34  std::function<GridBase*(void)> class_factory_function);
35 
36  // create an instance of a registered class
37  std::shared_ptr<GridBase> create(std::string class_name,
38  std::shared_ptr<phoxonics::core::SimulationConfig> sim_config);
39 
40 private:
41  // a private ctor
42  inline GridFactory() { };
43 
44  // the registry of factory functions
45  std::map<std::string, std::function<GridBase*(void)>> factory_function_registry_;
46 };
47 
48 } /* namespace core */
49 } /* namespace phoxonics */
50 
51 #endif /* GRIDFACTORY_HPP_ */
virtual ~GridFactory()
Definition: GridFactory.cpp:13
static GridFactory * instance()
Definition: GridFactory.cpp:17
Definition: CommonBase.hpp:14
std::shared_ptr< GridBase > create(std::string class_name, std::shared_ptr< phoxonics::core::SimulationConfig > sim_config)
Definition: GridFactory.cpp:30
Definition: FactoryBase.hpp:16
Definition: GridFactory.hpp:25
Definition: GridBase.hpp:26
void register_factory_function(std::string class_name, std::function< GridBase *(void)> class_factory_function)
Definition: GridFactory.cpp:22