valueFactory.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_VALUEFACTORY_HPP
2 #define JULIAN_VALUEFACTORY_HPP
3 
4 #include <map>
5 #include <string>
6 
7 namespace julian {
8 
21  template<class T>
22  class ValueFactory {
23  public:
24  static ValueFactory& instance();
25  T getValue(std::string name);
26  void registerValue(std::string,T);
27  private:
28  std::map<std::string,T> creators;
35 
41 
46  ValueFactory& operator=(const ValueFactory&){return *this;};
47  };
48 
51  template<class T>
53  static ValueFactory theFactory;
54  return theFactory;
55  }
56 
61  template<class T>
62  T ValueFactory<T>::getValue(std::string name) {
63  auto i = creators.find(name);
64  if ( i == creators.end() )
65  {
66  std::cout << name << " is an unknown name" << std::endl;
67  i == creators.begin();
68  }
69  return (i->second);
70  }
71 
77  template<class T>
78  void ValueFactory<T>::registerValue(std::string name, T x) {
79  creators.insert(std::pair<std::string,T>(name,x) );
80  }
81 
86  template <class T>
88  public:
89  ValueFactoryHelper(std::string,T value);
90 
91  };
92 
97  template <class T>
98  ValueFactoryHelper<T>::ValueFactoryHelper(std::string name, T value) {
100  factory.registerValue(name,value);
101  }
102 } // namespace julian
103 #endif
void registerValue(std::string, T)
registers an enumeration value
Definition: valueFactory.hpp:78
std::map< std::string, T > creators
Map holding the creators of class and their string codes.
Definition: valueFactory.hpp:28
ValueFactory(const ValueFactory &)
copy constructor
Definition: valueFactory.hpp:40
Definition: cadHoliday.cpp:3
ValueFactory()
constructor
Definition: valueFactory.hpp:34
ValueFactoryHelper(std::string, T value)
constructor
Definition: valueFactory.hpp:98
factory helper
Definition: valueFactory.hpp:87
T getValue(std::string name)
returns enumeration value
Definition: valueFactory.hpp:62
static ValueFactory & instance()
returns reference to instance of singleton factory
Definition: valueFactory.hpp:52
Class implements a factory pattern.
Definition: valueFactory.hpp:22
ValueFactory & operator=(const ValueFactory &)
assignment constructor
Definition: valueFactory.hpp:46