mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Bazaar/PolyXML - Added images on ClassFactory REGISTERCLASS()
git-svn-id: svn://ultimatepp.org/upp/trunk@1906 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
8a3f737d05
commit
53b63c14cc
1 changed files with 4 additions and 1 deletions
|
|
@ -14,21 +14,24 @@ template<class T> class WithFactory
|
|||
static VectorMap<String, String> &typeMap() { static VectorMap<String, String> tMap; return tMap; }
|
||||
static VectorMap<String, String> &descMap() { static VectorMap<String, String> dMap; return dMap; }
|
||||
static VectorMap<String, int> &indexMap() { static VectorMap<String, int> iMap; return iMap; }
|
||||
static VectorMap<String, Image> &imageMap() { static VectorMap<String, Image> imgMap; return imgMap; }
|
||||
template<class D> static One<T> __Create(void) { return One<T>((T *)new D); }
|
||||
public:
|
||||
|
||||
template<class D> static void Register(const String &name, const String &desc = "", int idx = 0)
|
||||
template<class D> static void Register(const String &name, const String &desc = "", int idx = 0, Image const &img = Null)
|
||||
{
|
||||
classMap().Add(name, __Create<D>);
|
||||
typeMap().Add(typeid(D).name(), name);
|
||||
descMap().Add(name, desc);
|
||||
indexMap().Add(name, idx);
|
||||
imageMap().Add(name, img);
|
||||
}
|
||||
static One<T> CreateInstance(const String &className) { return classMap().Get(className)(); }
|
||||
static T *CreatePtr(String const &className) { return classMap().Get(className)().Detach(); }
|
||||
static Vector<String> 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() {}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue