PetaVision  Alpha
Factory.hpp
1 /*
2  * Factory.hpp
3  *
4  * Created on: Jan 20, 2016
5  * Author: pschultz
6  */
7 
8 #ifndef FACTORY_HPP_
9 #define FACTORY_HPP_
10 
11 #include <columns/KeywordHandler.hpp>
12 #include <cstddef>
13 #include <vector>
14 
15 namespace PV {
16 
17 class BaseObject;
18 
66 class Factory {
67  public:
68  static Factory *instance() {
69  static Factory *singleton = new Factory();
70  return singleton;
71  }
72 
79  template <typename T>
80  static BaseObject *create(char const *name, HyPerCol *hc) {
81  return hc == nullptr ? nullptr : new T(name, hc);
82  }
83 
95  int registerKeyword(char const *keyword, ObjectCreateFn creator);
96 
104  BaseObject *createByKeyword(char const *keyword, char const *name, HyPerCol *hc) const;
105 
106  private:
112  Factory();
113 
117  virtual ~Factory();
118 
123  int registerCoreKeywords();
124 
130  int copyKeywordHandlerList(std::vector<KeywordHandler *> const &orig);
131 
136  KeywordHandler const *getKeywordHandler(char const *keyword) const;
137 
143 
144  // Member variables
145  private:
146  std::vector<KeywordHandler *> keywordHandlerList;
147 }; // class Factory
148 
149 } // namespace PV
150 
151 #endif /* FACTORY_HPP_ */
int registerKeyword(char const *keyword, ObjectCreateFn creator)
Definition: Factory.cpp:261
int copyKeywordHandlerList(std::vector< KeywordHandler * > const &orig)
Definition: Factory.cpp:254
virtual ~Factory()
Definition: Factory.cpp:302
KeywordHandler const * getKeywordHandler(char const *keyword) const
Definition: Factory.cpp:284
int registerCoreKeywords()
Definition: Factory.cpp:127
static BaseObject * create(char const *name, HyPerCol *hc)
Definition: Factory.hpp:80
BaseObject * createByKeyword(char const *keyword, char const *name, HyPerCol *hc) const
Definition: Factory.cpp:271
int clearKeywordHandlerList()
Definition: Factory.cpp:294