#ifndef __XMLIO_OBJECT_TEMPLATE__ #define __XMLIO_OBJECT_TEMPLATE__ // Classes utilisées issues de la STL using std::pair; using std::string; using std::ostream; using XMLIOSERVER::StrHashMap; namespace XMLIOSERVER { template class ObjectTemplate : public AbstractObject { public : static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) { // Si l'identifiant est répertorié, on retourne l'élément existant. if(ObjectTemplate::HasObject(_id)) return (ObjectTemplate::GetObject(_id)); // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié. ObjectTemplate::AllListObj[CurrContext].addObject(new T(_id)); return (ObjectTemplate::GetObject(_id)); } static T& CreateObject(void) { T* value = new T; ObjectTemplate::AllListObj[CurrContext].addObject(value); return (*value); } static T& GetObject(const string _id) throw (XMLIOUndefinedValueException) { return (*ObjectTemplate::AllListObj[CurrContext][_id]); } static bool HasObject(const string _id) { if(ObjectTemplate::AllListObj.find(CurrContext) == ObjectTemplate::AllListObj.end()) return false; return (ObjectTemplate::AllListObj[CurrContext].hasMappedValue(_id)); } static const StrHashMap& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } static HashMap >& GetAllListObject(void) { return (AllListObj); } static void SetContext(const string& id){ ObjectTemplate::CurrContext = id; } static string& GetCurrentContextId(void) { return (CurrContext); } virtual ~ObjectTemplate(void) {/* Ne rien faire de plus */} protected : ObjectTemplate(void) : AbstractObject() {/* Ne rien faire de plus */} ObjectTemplate(const string& _id) : AbstractObject(_id) {/* Ne rien faire de plus */} private : static string CurrContext; static HashMap > AllListObj; };// class ObjectTemplate template string ObjectTemplate::CurrContext ; template HashMap > ObjectTemplate::AllListObj; }// namespace XMLIOSERVER #endif // __XMLIO_OBJECT_TEMPLATE__