Phoxonics  1.0
Object Oriented FDTD Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EngineFactory.hpp
Go to the documentation of this file.
1 /*
2  * EngineFactory.hpp
3  *
4  * Created on: Oct 24, 2014
5  * Author: cuda
6  */
7 
8 #ifndef ENGINEFACTORY_HPP_
9 #define ENGINEFACTORY_HPP_
10 
11 #include "EngineBase.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 EngineFactory : public FactoryBase {
26 public:
27  virtual ~EngineFactory();
28 
29  // Get the single instance of the factory
30  static EngineFactory* 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<EngineBase*(void)> class_factory_function);
35 
36  // create an instance of a registered class
37  std::shared_ptr<EngineBase> create(std::string class_name,
38  std::shared_ptr<phoxonics::core::SimulationConfig> sim_config);
39 
40 private:
41  // a private ctor
42  inline EngineFactory() { };
43 
44  // the registry of factory functions
45  std::map<std::string, std::function<EngineBase*(void)>> factory_function_registry_;
46 };
47 
48 } /* namespace core */
49 } /* namespace phoxonics */
50 
51 #endif /* ENGINEFACTORY_HPP_ */
Definition: CommonBase.hpp:14
Definition: FactoryBase.hpp:16
static EngineFactory * instance()
Definition: EngineFactory.cpp:17
void register_factory_function(std::string class_name, std::function< EngineBase *(void)> class_factory_function)
Definition: EngineFactory.cpp:22
Definition: EngineBase.hpp:26
virtual ~EngineFactory()
Definition: EngineFactory.cpp:13
Definition: EngineFactory.hpp:25
std::shared_ptr< EngineBase > create(std::string class_name, std::shared_ptr< phoxonics::core::SimulationConfig > sim_config)
Definition: EngineFactory.cpp:30