#ifndef oo_ObjSelector_H__ #define oo_ObjSelector_H__ #include "ObjBase.h" #include namespace meow{ template class ObjSelector{ private: typedef std::map Funcs; typedef std::vector Types; // static Funcs& funcs(){ static Funcs f; return f; } // std::string name; ObjBase* ptr; public: ObjSelector( ObjBase* o){ add(name = o->type(), ptr = o); } ObjSelector(std::string n, ObjBase* o){ add(name = n , ptr = o); } ~ObjSelector(){ del(name); } // static void add(std::string n, ObjBase* b){ del(n); funcs()[n] = b; } static void del(std::string s){ if(funcs().find(s) != funcs().end()){ delete funcs()[s]; funcs().erase(s); } } static ObjBase* get(std::string s){ if(funcs().find(s) == funcs().end() || funcs()[s] == NULL) return NULL; return funcs()[s]->create(); } static Types lst(){ Types ret; for(Funcs::iterator it = funcs().begin(); it != funcs().end(); it++) ret.push_back(it->first); return ret; } }; } #endif // oo_ObjSelector_H__