#ifndef __XIOS_CObjectFactory_impl__ #define __XIOS_CObjectFactory_impl__ #include "object_factory.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// template int CObjectFactory::GetObjectNum(void) { if (CurrContext_ptr->size() == 0) ERROR("CObjectFactory::GetObjectNum(void)", << "please define current context id !"); if(U::AllVectObj == NULL) return 0; return (*U::AllVectObj)[*CObjectFactory::CurrContext_ptr].size(); } template int CObjectFactory::GetObjectIdNum(void) { if (CurrContext_ptr->size() == 0) ERROR("CObjectFactory::GetObjectIdNum(void)", << "please define current context id !"); if(U::AllMapObj == NULL) return 0; return (* U::AllMapObj) [*CObjectFactory::CurrContext_ptr].size(); } template bool CObjectFactory::HasObject(const StdString & id) { if (CurrContext_ptr->size() == 0) ERROR("CObjectFactory::HasObject(const StdString & id)", << "[ id = " << id << " ] please define current context id !"); if(U::AllMapObj == NULL) return false; return ((*U::AllMapObj)[*CObjectFactory::CurrContext_ptr].find(id) != (*U::AllMapObj)[*CObjectFactory::CurrContext_ptr].end()); } template bool CObjectFactory::HasObject(const StdString & context, const StdString & id) { if(U::AllMapObj == NULL) return false; if (U::AllMapObj->find(context) == U::AllMapObj->end()) return false ; else { return ((*U::AllMapObj)[context].find(id) != (*U::AllMapObj)[context].end()); } } template boost::shared_ptr CObjectFactory::GetObject(const U * const object) { if(U::AllVectObj == NULL) return (boost::shared_ptr()); if (CurrContext_ptr->size() == 0) ERROR("CObjectFactory::GetObject(const U * const object)", << "please define current context id !"); std::vector > & vect = (*U::AllVectObj)[*CObjectFactory::CurrContext_ptr]; typename std::vector >::const_iterator it = vect.begin(), end = vect.end(); for (; it != end; it++) { boost::shared_ptr ptr = *it; if (ptr.get() == object) return (ptr); } ERROR("CObjectFactory::GetObject(const U * const object)", << "[type = " << U::GetName() << ", adress = " << object << "] " << "object was not found."); return (boost::shared_ptr()); // jamais atteint } template boost::shared_ptr CObjectFactory::GetObject(const StdString & id) { if(U::AllMapObj == NULL) return (boost::shared_ptr()); if (CurrContext_ptr->size() == 0) ERROR("CObjectFactory::GetObject(const StdString & id)", << "[ id = " << id << " ] please define current context id !"); if (!CObjectFactory::HasObject(id)) ERROR("CObjectFactory::GetObject(const StdString & id)", << "[ id = " << id << ", U = " << U::GetName() << " ] " << "object was not found."); return (*U::AllMapObj)[*CObjectFactory::CurrContext_ptr][id]; } template boost::shared_ptr CObjectFactory::GetObject(const StdString & context, const StdString & id) { if(U::AllMapObj == NULL) return (boost::shared_ptr()); if (!CObjectFactory::HasObject(context,id)) ERROR("CObjectFactory::GetObject(const StdString & id)", << "[ id = " << id << ", U = " << U::GetName() <<", context = "< boost::shared_ptr CObjectFactory::CreateObject(const StdString& id) { if(U::AllVectObj == NULL) U::AllVectObj = new xios_map > >; if(U::AllMapObj == NULL) U::AllMapObj = new xios_map > >; if (CurrContext_ptr->empty()) ERROR("CObjectFactory::CreateObject(const StdString& id)", << "[ id = " << id << " ] please define current context id !"); if (CObjectFactory::HasObject(id)) { return CObjectFactory::GetObject(id); } else { boost::shared_ptr value(new U(id.empty() ? CObjectFactory::GenUId() : id)); (* U::AllVectObj)[*CObjectFactory::CurrContext_ptr].insert((*U::AllVectObj)[*CObjectFactory::CurrContext_ptr].end(), value); (* U::AllMapObj) [*CObjectFactory::CurrContext_ptr].insert(std::make_pair(value->getId(), value)); return value; } } template const std::vector > & CObjectFactory::GetObjectVector(const StdString & context) { if(U::AllVectObj != NULL) return (*U::AllVectObj)[context]; } template const StdString& CObjectFactory::GetUIdBase(void) { static const StdString base = "__" + U::GetName() + "_undef_id_"; return base; } template StdString CObjectFactory::GenUId(void) { StdOStringStream oss; if(U::GenId == NULL) U::GenId = new xios_map< StdString, long int >; oss << GetUIdBase() << (*U::GenId)[*CObjectFactory::CurrContext_ptr]++; return oss.str(); } template bool CObjectFactory::IsGenUId(const StdString& id) { const StdString& base = GetUIdBase(); return (id.size() > base.size() && id.compare(0, base.size(), base) == 0); } } // namespace xios #endif // __XIOS_CObjectFactory_impl__