1 #ifndef MSP_DATAFILE_LOADABLETYPEREGISTRY_H_
2 #define MSP_DATAFILE_LOADABLETYPEREGISTRY_H_
7 #include <msp/core/attributes.h>
8 #include <msp/core/maputils.h>
9 #include <msp/core/noncopyable.h>
15 Associates types with keywords for adding to a Loader. The target Loader class
16 must be given as a template parameter, as well as a helper template struct to
17 handle the actual adding of keywords.
19 Deprecated; use TypeRegistry from mspcore instead.
21 template<typename L, template<typename> class A>
22 class DEPRECATED LoadableTypeRegistry: private NonCopyable
30 TypeBase(const std::string &kw): keyword(kw) { }
32 virtual ~TypeBase() { }
34 virtual void add(L &) const = 0;
38 class RegisteredType: public TypeBase
41 RegisteredType(const std::string &kw): TypeBase(kw) { }
43 virtual void add(L &ldr) const { A<T>::add(ldr, this->keyword); }
46 typedef std::map<std::string, TypeBase *> TypeMap;
51 ~LoadableTypeRegistry();
54 void register_type(const std::string &);
56 void add_all(L &) const;
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
61 template<typename L, template<typename> class A>
62 LoadableTypeRegistry<L, A>::~LoadableTypeRegistry()
64 for(typename TypeMap::iterator i=types.begin(); i!=types.end(); ++i)
68 template<typename L, template<typename> class A>
70 void LoadableTypeRegistry<L, A>::register_type(const std::string &kw)
75 types[kw] = new RegisteredType<T>(kw);
78 template<typename L, template<typename> class A>
79 void LoadableTypeRegistry<L, A>::add_all(L &ldr) const
81 for(typename TypeMap::const_iterator i=types.begin(); i!=types.end(); ++i)
84 #pragma GCC diagnostic pop
86 } // namespace DataFile