Changeset 107 for XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp
- Timestamp:
- 06/17/10 16:44:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp
r104 r107 1 1 #ifndef __XMLIO_OBJECT_TEMPLATE__ 2 #define __XMLIO_OBJECT_TEMPLATE__ 2 #define __XMLIO_OBJECT_TEMPLATE__ 3 4 #include "declare_attribut.hpp" 5 #include "attribut_registrar.hpp" 3 6 4 7 // Classes utilisées issues de la STL … … 8 11 9 12 using XMLIOSERVER::StrHashMap; 10 13 14 using XMLIOSERVER::XML::XMLNode; 15 using XMLIOSERVER::XML::THashAttributes; 16 11 17 namespace XMLIOSERVER 12 18 { 13 19 template <class T> 14 class ObjectTemplate : public AbstractObject 20 class ObjectTemplate : public AbstractObject, public virtual AttributRegistrar 15 21 { 16 22 public : 17 18 static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) 23 24 25 friend ostream& operator<< (ostream& out, const T& c) 26 { 27 const AttributRegistrar &ar = c; 28 if (c.hasChild()) 29 { 30 out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl; 31 c.printChild(out); // << Ecriture des objets enfants ici. 32 out << NIndent << "</" << c.getName() << ">" << DecEndl; 33 } 34 else out << IncIndent << "<" << c.getName() << c.printId() << ar << "/>" << DecEndl; 35 36 return (out); 37 } 38 39 string getName(void) const {return (T::GetName()); } 40 41 virtual bool hasChild(void) const { return (false); } 42 virtual void printChild(ostream& out) const { /* Ne rien faire de plus */ } 43 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) { addAttributes(*_parent); } 44 45 static T& CreateObject(const string _id) throw (XMLIOUndefinedValueException) 19 46 { 20 47 // Si l'identifiant est répertorié, on retourne l'élément existant. 21 48 if(ObjectTemplate<T>::HasObject(_id)) 22 49 return (ObjectTemplate<T>::GetObject(_id)); 23 24 // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié. 50 51 // Ajout d'un nouvel objet si l'identifiant n'est pas répertorié. 25 52 ObjectTemplate<T>::AllListObj[CurrContext].addObject(new T(_id)); 26 53 27 54 return (ObjectTemplate<T>::GetObject(_id)); 28 55 } 29 56 30 57 static T& CreateObject(void) 31 58 { … … 34 61 return (*value); 35 62 } 36 63 37 64 static T& GetObject(const string _id) throw (XMLIOUndefinedValueException) 38 65 { return (*ObjectTemplate<T>::AllListObj[CurrContext][_id]); } 39 66 40 67 static bool HasObject(const string _id) 41 68 { … … 43 70 return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); 44 71 } 45 72 46 73 static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } 47 74 static HashMap<string, StrHashMap<T> >& GetAllListObject(void) { return (AllListObj); } 48 49 static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } 50 51 static string& GetCurrentContextId(void) { return (CurrContext); } 52 75 76 static void SetContext(const string& id){ ObjectTemplate<T>::CurrContext = id; } 77 78 static string& GetCurrentContextId(void) { return (CurrContext); } 79 53 80 virtual ~ObjectTemplate(void) 54 81 {/* Ne rien faire de plus */} 55 82 56 83 protected : 57 84 58 85 ObjectTemplate(void) : AbstractObject() 59 {/* Ne rien faire de plus */}60 ObjectTemplate(const string& _id) : AbstractObject(_id)61 86 {/* Ne rien faire de plus */} 62 87 ObjectTemplate(const string& _id) : AbstractObject(_id) 88 {/* Ne rien faire de plus */} 89 90 XML::XMLNode getNodeIncludedFile(const string& path, const string& _rootName) 91 { 92 ifstream istr( path.c_str() , ifstream::in ); 93 return XML::XMLNode::CreateNode(istr, _rootName); 94 } 95 96 template <class V> static V* CreateInstanceAndParse( THashAttributes& attributes, XMLNode& _node, const char* defaultId, bool parseAttr = true ) 97 { 98 V* instance_ptr = NULL; string did(defaultId); 99 if (defaultId != NULL) 100 { 101 if (V::HasObject(did)) 102 WARNING("Le noeud nommé "+ did +" existe déjà pour les instances de type "+V::GetName()+", le dernier défini complétera le premier dans le context actuel!"); 103 instance_ptr = (V*)&V::CreateObject(did); 104 instance_ptr->parse(_node, parseAttr); 105 } 106 return (instance_ptr); 107 } 108 63 109 private : 64 110 65 111 static string CurrContext; 66 112 static HashMap<string, StrHashMap<T> > AllListObj; 67 113 68 114 };// class ObjectTemplate 69 115 70 116 template <class T> string ObjectTemplate<T>::CurrContext ; 71 117 template <class T> HashMap<string, StrHashMap<T> > ObjectTemplate<T>::AllListObj; 72 118 73 119 }// namespace XMLIOSERVER 74 75 #endif // __XMLIO_OBJECT_TEMPLATE__ 120 121 #endif // __XMLIO_OBJECT_TEMPLATE__
Note: See TracChangeset
for help on using the changeset viewer.