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