#ifndef _ClassFactory_h_ #define _ClassFactory_h_ #include NAMESPACE_UPP; template class WithFactory { private: typedef One (*CreateFunc)(); typedef VectorMapmapType; static mapType &classMap() { static mapType cMap; return cMap; } static VectorMap &typeMap() { static VectorMap tMap; return tMap; } static VectorMap &descMap() { static VectorMap dMap; return dMap; } static VectorMap &indexMap() { static VectorMap iMap; return iMap; } static VectorMap &imageMap() { static VectorMap imgMap; return imgMap; } template static One __Create(void) { return One((T *)new D); } public: template static void Register(const String &name, const String &desc = "", int idx = 0, Image const &img = Null) { classMap().Add(name, __Create); typeMap().Add(typeid(D).name(), name); descMap().Add(name, desc); indexMap().Add(name, idx); imageMap().Add(name, img); } static One CreateInstance(const String &className) { return classMap().Get(className)(); } static T *CreatePtr(String const &className) { return classMap().Get(className)().Detach(); } static Vector const &Classes(void) { return classMap().GetKeys(); } static String const &GetClassDescription(const String &className) { return descMap().Get(className); } static int const &GetClassIndex(const String &className) { return indexMap().Get(className); } static Image const &GetClassImage(const String &className) { return imageMap().Get(className); } String const &IsA(void) { return typeMap().Get(typeid(*this).name()); } virtual ~WithFactory() {} }; #ifdef COMPILER_MSC #define REGISTERCLASS(type, ...) \ INITBLOCK { \ type::Register(#type, __VA_ARGS__); \ } #else #define REGISTERCLASS(type, ...) \ INITBLOCK { \ type::Register(#type, ##__VA_ARGS__); \ } #endif END_UPP_NAMESPACE; #endif