Making old and new Factory code more coherent.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@788 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
clitte_bbt 2006-11-24 22:30:54 +00:00
parent b072da9f73
commit 325c79f896

View file

@ -799,7 +799,6 @@ template <typename AP, typename Id, typename P1 >
ProductCreator creator( p, fn ); ProductCreator creator( p, fn );
return associations_.insert( return associations_.insert(
typename IdToProductMap::value_type(id, creator)).second != 0; typename IdToProductMap::value_type(id, creator)).second != 0;
} }
bool Unregister(const IdentifierType& id) bool Unregister(const IdentifierType& id)
@ -977,7 +976,6 @@ template <typename AP, typename Id, typename P1 >
}; };
#else #else
template template
@ -995,12 +993,12 @@ template <typename AP, typename Id, typename P1 >
bool Register(const IdentifierType& id, ProductCreator creator) bool Register(const IdentifierType& id, ProductCreator creator)
{ {
return associations_.insert( return associations_.insert(
typename IdToProductMap::value_type(id, creator)).second; typename IdToProductMap::value_type(id, creator)).second != 0;
} }
bool Unregister(const IdentifierType& id) bool Unregister(const IdentifierType& id)
{ {
return associations_.erase(id) == 1; return associations_.erase(id) != 0;
} }
AbstractProduct* CreateObject(const IdentifierType& id) AbstractProduct* CreateObject(const IdentifierType& id)
@ -1018,7 +1016,6 @@ template <typename AP, typename Id, typename P1 >
IdToProductMap associations_; IdToProductMap associations_;
}; };
#endif //#define ENABLE_NEW_FACTORY_CODE #endif //#define ENABLE_NEW_FACTORY_CODE
/** /**
@ -1046,20 +1043,24 @@ template <typename AP, typename Id, typename P1 >
bool Register(const TypeInfo& ti, ProductCreator creator) bool Register(const TypeInfo& ti, ProductCreator creator)
{ {
return associations_.insert( return associations_.insert(
typename IdToProductMap::value_type(ti, creator)).second; typename IdToProductMap::value_type(ti, creator)).second != 0;
} }
bool Unregister(const TypeInfo& id) bool Unregister(const TypeInfo& id)
{ {
return associations_.erase(id) == 1; return associations_.erase(id) != 0;
} }
AbstractProduct* CreateObject(const AbstractProduct* model) AbstractProduct* CreateObject(const AbstractProduct* model)
{ {
if (model == 0) return 0; if (model == NULL)
{
return NULL;
}
typename IdToProductMap::iterator i = typename IdToProductMap::iterator i =
associations_.find(typeid(*model)); associations_.find(typeid(*model));
if (i != associations_.end()) if (i != associations_.end())
{ {
return (i->second)(model); return (i->second)(model);
@ -1071,12 +1072,13 @@ template <typename AP, typename Id, typename P1 >
typedef AssocVector<TypeInfo, ProductCreator> IdToProductMap; typedef AssocVector<TypeInfo, ProductCreator> IdToProductMap;
IdToProductMap associations_; IdToProductMap associations_;
}; };
} // namespace Loki } // namespace Loki
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( pop ) #pragma warning( pop )
#endif #endif
#endif // end file guardian #endif // end file guardian