10 #ifndef KTTIFACTORY_HH_ 11 #define KTTIFACTORY_HH_ 15 #include "singleton.hh" 24 template<
class XBaseType >
27 template<
class XBaseType >
38 virtual XBaseType*
Create()
const = 0;
42 template<
class XBaseType,
class XDerivedType >
50 void Register()
const;
57 template<
class XBaseType >
58 class KTTIFactory :
public scarab::singleton< KTTIFactory< XBaseType > >
63 bool operator() (
const std::type_info* lhs,
const std::type_info* rhs)
65 return lhs->before(*rhs);
70 typedef std::map< const std::type_info*, const KTTIRegistrarBase< XBaseType >* >
FactoryMap;
76 template<
class XDerivedType >
79 XBaseType*
Create(
const FactoryCIt& iter);
81 template<
class XDerivedType >
84 FactoryCIt GetFactoryMapBegin()
const;
85 FactoryCIt GetFactoryMapEnd()
const;
98 template<
class XBaseType >
99 template<
class XDerivedType >
102 FactoryCIt it = fMap->find(&
typeid(XDerivedType));
103 if (it == fMap->end())
109 return it->second->Create();
112 template<
class XBaseType >
115 return iter->second->Create();
118 template<
class XBaseType >
119 template<
class XDerivedType >
123 KTLOGGER(utillog_ti_factory_reg,
"KTTIFactory-Register");
125 FactoryCIt it = fMap->find(&
typeid(XDerivedType));
126 if (it != fMap->end())
128 KTERROR(utillog_ti_factory_reg,
"Already have factory registered for type <" <<
typeid(XDerivedType).name() <<
">.");
132 KTDEBUG(utillog_ti_factory_reg,
"Registered a factory for class type " <<
typeid(XDerivedType).name() <<
", factory #" << fMap->size()-1);
135 template<
class XBaseType >
140 template<
class XBaseType >
146 template<
class XBaseType >
149 return fMap->begin();
152 template<
class XBaseType >
161 template<
class XBaseType,
class XDerivedType >
168 template<
class XBaseType,
class XDerivedType >
172 template<
class XBaseType,
class XDerivedType >
179 template<
class XBaseType,
class XDerivedType >
182 return dynamic_cast< XBaseType*
>(
new XDerivedType());
virtual ~KTTIRegistrarBase()
FactoryMap::const_iterator FactoryCIt
FactoryMap::value_type FactoryEntry
FactoryCIt GetFactoryMapEnd() const
FactoryMap::iterator FactoryIt
FactoryCIt GetFactoryMapBegin() const
KTLOGGER(applog, "KTApplication")
XBaseType * Create() const
virtual XBaseType * Create() const =0
void Register(const KTTIRegistrarBase< XBaseType > *registrar)
std::map< const std::type_info *, const KTTIRegistrarBase< XBaseType > *> FactoryMap
::Nymph::KTLogger utillog_ti_factory("KTTIFactory")
Contains the logger class and macros, based on Kasper's KLogger class.