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