X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Floadabletyperegistry.h;h=ace98cbc11d0e09d5aa2842d67c6677c87b2ecd5;hb=HEAD;hp=7b027cd5737d62bc4022ec71b3bb25635e96ded5;hpb=e1b8089be727f651fc2022d6e7ff775047730e85;p=libs%2Fdatafile.git diff --git a/source/loadabletyperegistry.h b/source/loadabletyperegistry.h deleted file mode 100644 index 7b027cd..0000000 --- a/source/loadabletyperegistry.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef MSP_DATAFILE_LOADABLETYPEREGISTRY_H_ -#define MSP_DATAFILE_LOADABLETYPEREGISTRY_H_ - -#include -#include -#include -#include -#include - -namespace Msp { -namespace DataFile { - -/** -Associates types with keywords for adding to a Loader. The target Loader class -must be given as a template parameter, as well as a helper template struct to -handle the actual adding of keywords. -*/ -template class A> -class LoadableTypeRegistry: private NonCopyable -{ -private: - class TypeBase - { - protected: - std::string keyword; - - TypeBase(const std::string &kw): keyword(kw) { } - public: - virtual ~TypeBase() { } - - virtual void add(L &) const = 0; - }; - - template - class RegisteredType: public TypeBase - { - public: - RegisteredType(const std::string &kw): TypeBase(kw) { } - - virtual void add(L &ldr) const { A::add(ldr, this->keyword); } - }; - - typedef std::map TypeMap; - - TypeMap types; - -public: - ~LoadableTypeRegistry(); - - template - void register_type(const std::string &); - - void add_all(L &) const; -}; - -template class A> -LoadableTypeRegistry::~LoadableTypeRegistry() -{ - for(typename TypeMap::iterator i=types.begin(); i!=types.end(); ++i) - delete i->second; -} - -template class A> -template -void LoadableTypeRegistry::register_type(const std::string &kw) -{ - if(types.count(kw)) - throw key_error(kw); - - types[kw] = new RegisteredType(kw); -} - -template class A> -void LoadableTypeRegistry::add_all(L &ldr) const -{ - for(typename TypeMap::const_iterator i=types.begin(); i!=types.end(); ++i) - i->second->add(ldr); -} - -} // namespace DataFile -} // namespace Msp - -#endif