diff --git a/bazaar/PolyXML/ClassFactory.h b/bazaar/PolyXML/ClassFactory.h index 6af32198f..111c39ea4 100644 --- a/bazaar/PolyXML/ClassFactory.h +++ b/bazaar/PolyXML/ClassFactory.h @@ -13,12 +13,15 @@ template class WithFactory 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 &indexMap() { static VectorMap iMap; return iMap; } static VectorMap &imageMap() { static VectorMap imgMap; return imgMap; } + + static VectorMap &groupDescMap() { static VectorMap grpDescMap; return grpDescMap; } + static VectorMap &groupIconMap() { static VectorMap grpIcnMap; return grpIcnMap; } 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) + template static void Register(const String &name, const String &desc = "", dword idx = 0, Image const &img = Null) { classMap().Add(name, __Create); typeMap().Add(typeid(D).name(), name); @@ -30,9 +33,62 @@ template class WithFactory 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 dword 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()); } + + // class groups handling + static void RegisterClassGroupIcon(dword gMask, String const &desc, Image const &img) { groupIconMap().FindAdd(gMask, img); groupDescMap().FindAdd(gMask, desc); } + static Image const &GetGroupIcon(dword gMask) + { + static Image nullImage; + int idx = groupIconMap().Find(gMask); + if(idx != -1) + return groupIconMap().operator[](idx); + else + return nullImage; + } + static String GetGroupDesc(dword gMask) + { + int idx = groupDescMap().Find(gMask); + if(idx != -1) + return groupDescMap().operator[](idx); + else + return ""; + } + static VectorGetGroupIndexes(dword groupMask, dword forceMask = 0, dword forceVal = 0) + { + Index idx; + Vector allIdx; + allIdx <<= groupDescMap().GetKeys(); + for(int i = 0; i < allIdx.GetCount(); i++) + { + dword ci = allIdx.operator[](i); + if( ((ci & forceMask) == (forceVal & forceMask)) && (ci & groupMask)) + idx.FindAdd((ci & groupMask) | (forceMask & forceVal)); + } + Vectorres = idx.PickKeys(); + Sort(res); + return res; + } + static VectorGetGroupClasses(dword gMask) + { + Vectornames; + Vectorindexes; + VectorMap const &iMap = indexMap(); + for(int i = 0; i < iMap.GetCount(); i++) + { + dword ci = iMap.operator[](i); + if((gMask & ci) == gMask) + { + names.Add(iMap.GetKey(i)); + indexes.Add(ci); + } + } + IndexSort(indexes, names); + return names; + } + virtual ~WithFactory() {} }; @@ -48,6 +104,10 @@ template class WithFactory } #endif +#define REGISTERCLASSGROUPICON(type, groupMask, desc, icon) \ + INITBLOCK { \ + type::RegisterClassGroupIcon(groupMask, desc, icon); \ + } END_UPP_NAMESPACE; #endif