gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
factory_registry.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
30 
31 #ifndef __factory_registry_hpp__
32 #define __factory_registry_hpp__
33 
34 #include <type_traits>
35 #include <utility>
36 #include <ostream>
37 #include <sstream>
38 #include <unordered_map>
39 #include <algorithm>
40 
41 #define REGISTER(reg_map, tag, ...) REGISTER_ELEM(reg_map, #tag, __VA_ARGS__)
42 
43 #define REGISTER_ELEM(reg_map, tag, ...) \
44 namespace __gambit_registry__ \
45 { \
46  namespace \
47  { \
48  template<> \
49  class __create_class__ < __VA_ARGS__ > \
50  { \
51  public: \
52  __create_class__(decltype(reg_map) &creators) \
53  { \
54  creators[ tag ] = __create_class__< __VA_ARGS__ >::init; \
55  } \
56  \
57  template<typename T, typename... args> \
58  static T *init(args... params) \
59  { \
60  return static_cast<T *>(new __VA_ARGS__ (std::forward<args>(params)...)); \
61  } \
62  }; \
63  \
64  template <> \
65  __create_class__ < __VA_ARGS__ > __reg_init__ < __VA_ARGS__ >::reg(reg_map); \
66  } \
67 } \
68 
69 #define gambit_registry \
70 namespace __gambit_registry__ \
71 { \
72  namespace \
73  { \
74  template <class T> \
75  class __create_class__ {}; \
76  \
77  template <class T> \
78  struct __reg_init__ \
79  { \
80  static __create_class__ <T> reg; \
81  }; \
82  } \
83 } \
84  \
85 namespace \
86 
87 
88 namespace Gambit
89 {
90 
91  template <typename T>
92  class reg_elem : public std::unordered_map<std::string, T *>
93  {
94  private:
95 
96  public:
97  std::string print()
98  {
99  std::ostringstream out;
100 
101  out << "The options are: \n";
102  for (auto it = this->begin(); it != this->end(); it++)
103  {
104  out << "\t" << it->first << "\n";
105  }
106 
107  return out.str();
108  }
109  };
110 }
111 
112 #endif
std::string print()
TODO: see if we can use this one:
Definition: Analysis.hpp:33