1 #ifndef MSP_DATAFILE_LOADABLETYPEREGISTRY_H_
2 #define MSP_DATAFILE_LOADABLETYPEREGISTRY_H_
7 #include <msp/core/maputils.h>
8 #include <msp/core/noncopyable.h>
14 Associates types with keywords for adding to a Loader. The target Loader class
15 must be given as a template parameter, as well as a helper template struct to
16 handle the actual adding of keywords.
18 template<typename L, template<typename> class A>
19 class LoadableTypeRegistry: private NonCopyable
27 TypeBase(const std::string &kw): keyword(kw) { }
29 virtual ~TypeBase() { }
31 virtual void add(L &) const = 0;
35 class RegisteredType: public TypeBase
38 RegisteredType(const std::string &kw): TypeBase(kw) { }
40 virtual void add(L &ldr) const { A<T>::add(ldr, this->keyword); }
43 typedef std::map<std::string, TypeBase *> TypeMap;
48 ~LoadableTypeRegistry();
51 void register_type(const std::string &);
53 void add_all(L &) const;
56 template<typename L, template<typename> class A>
57 LoadableTypeRegistry<L, A>::~LoadableTypeRegistry()
59 for(typename TypeMap::iterator i=types.begin(); i!=types.end(); ++i)
63 template<typename L, template<typename> class A>
65 void LoadableTypeRegistry<L, A>::register_type(const std::string &kw)
70 types[kw] = new RegisteredType<T>(kw);
73 template<typename L, template<typename> class A>
74 void LoadableTypeRegistry<L, A>::add_all(L &ldr) const
76 for(typename TypeMap::const_iterator i=types.begin(); i!=types.end(); ++i)
80 } // namespace DataFile