Changeset 107
- Timestamp:
- 06/17/10 16:44:31 (14 years ago)
- Location:
- XMLIO_V2/dev/dev_rv/src/XMLIO
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut_registrar.hpp
r106 r107 11 11 { 12 12 public : 13 13 14 14 AttributRegistrar():attrList() 15 15 {/* Ne rien faire de plus */} 16 17 void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); } 18 const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); } 16 17 void RegisterAttribut(BaseAttribut* attribut){ attrList.addObject(attribut); } 18 const StrHashMap<BaseAttribut>& getAttributList(void) const { return (attrList); } 19 19 size_t getNbAttributes() const {return (attrList.getSize()); } 20 20 bool hasAttribut(const string& _id) { return (attrList.hasMappedValue(_id)); } 21 21 22 22 BaseAttribut* getAttribut(const string& _id) throw (XMLIOUndefinedValueException) { return (attrList[_id]); } 23 24 friend ostream& operator<< (ostream& out, const AttributRegistrar& c) 25 { 26 for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; 23 24 friend ostream& operator<< (ostream& out, const AttributRegistrar& c) 25 { 26 for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; 27 27 return (out); 28 } 29 30 28 } 29 31 30 void setAttributes(const THashAttributes& _attr) 32 31 { … … 34 33 if ((*it).first.compare(string("id"))!= 0 and (*it).first.compare(string("src"))!=0) 35 34 // (Au dessus) Non prise en compte de l'identifiant et de l'inclusion de fichiers externes lors de l'affectation des attributs. 36 this->setSAttribut((*it).first, (*it).second); 35 this->setSAttribut((*it).first, (*it).second); 37 36 return; 38 37 } 39 38 40 39 void addAttributes(const AttributRegistrar& _parent) 41 { 40 { 42 41 const StrHashMap<BaseAttribut>& _pattr = _parent.getAttributList(); 43 const StrHashMap<BaseAttribut>& _lattr = getAttributList(); 42 const StrHashMap<BaseAttribut>& _lattr = getAttributList(); 44 43 //_pattr contient les attributs du parent, _lattr les attributs locaux. 45 44 46 45 for(unsigned int i = 0; i < _lattr.getVectorSize(); i++) 47 46 { … … 50 49 } 51 50 } 52 51 53 52 void setSAttribut(const string& att_name, const std::string& value) 54 53 { … … 62 61 oss << "CAttributRegistrar::setAttribut<ValueType>, could not find <<" << att_name <<">> attribut in registred list" <<">>"; 63 62 throw XMLIOUndefinedValueException(oss.str()); 64 } 63 } 65 64 } 66 65 67 66 public : 68 67 69 68 ~AttributRegistrar(void) 70 69 {/* Ne rien faire de plus */} 71 70 72 71 protected : 73 72 StrHashMap<BaseAttribut> attrList; 74 75 }; // class AttributRegistrar 73 74 75 }; // class AttributRegistrar 76 76 }; // namespace XMLIOSERVER 77 77 -
XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp
r106 r107 1 1 #ifndef __CONTEXT__ 2 #define __CONTEXT__ 2 #define __CONTEXT__ 3 3 4 4 5 5 namespace XMLIOSERVER 6 { 6 { 7 7 class Context : public ObjectTemplate<Context> 8 8 { 9 9 public: 10 11 Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL) 12 {/* Ne rien faire de plus */} 13 Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL), fileDef(NULL) 10 11 Context(void) : ObjectTemplate<Context>(), fieldDef(NULL), fileDef(NULL)//, axisDef(NULL), gridDef(NULL) 14 12 {/* Ne rien faire de plus */} 15 13 Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL), fileDef(NULL)//, axisDef(NULL), gridDef(NULL) 14 {/* Ne rien faire de plus */} 15 16 static void ShowTree(ostream& os = std::clog) 17 { 18 clog << "<?xml version=\"1.0\"?>" << std::endl; 19 clog << "<simulation>" << std::endl; 20 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 21 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 22 // On sort chacun des contextes successivement. 23 clog << *((*it).second)[(*it).first] << std::endl; 24 clog << "</simulation>" << std::endl ; 25 } 26 27 static void FreeMemory(void) 28 { 29 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 30 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 31 { Context::SetCurrentContext((*it).first); delete ((*it).second)[(*it).first]; } 32 } 33 34 static void ResolveInheritance(void) 35 { 36 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 37 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 38 // Résolution des héritages des descendands (cà d des héritages de groupes) pour chacun des contextes. 39 ((*it).second)[(*it).first]->resolveDescInheritance(); 40 } 41 16 42 static void SetCurrentContext(const string& id) 17 43 { 18 44 // On modifie le context courrant pour tout les ObjectTemplate 19 45 Context::SetContext(id); 20 46 21 47 // Changement de context pour les champs et groupes de champs. 22 48 FieldGroup::SetContext(id); 23 49 CField::SetContext(id); 24 25 // Changement de context pour les champs et groupes de champs.50 51 // Changement de context pour les fichiers et groupes de fichiers. 26 52 FileGroup::SetContext(id); 27 53 CFile::SetContext(id); 54 55 // Changement de context pour les grilles et groupes de grilles. 56 //GridGroup::SetContext(id); 57 //CGrid::SetContext(id); 58 59 // Changement de context pour les axes et groupes d'axes. 60 //AxisGroup::SetContext(id); 61 //CAxis::SetContext(id); 28 62 } 29 30 friend ostream& operator<< (ostream& out, const Context& c) 31 { 32 out << IncIndent << "<" << c.getName()<< " id=\"" << c.getId() << "\">" << std::endl; 33 34 if(c.fieldDef != NULL) out << *(FieldGroup*)c.fieldDef << std::endl; 35 if(c.fileDef != NULL) out << *(FileGroup*) c.fileDef << std::endl; 36 37 out << NIndent << "</" << c.getName()<< ">" << DecEndl; 38 return (out); 39 } 40 41 void resolveDescInheritance(void) 63 64 void parse (XMLNode& _node) 65 { 66 THashAttributes attributes; 67 68 /// PARSING POUR GESTION DES ENFANTS 69 if (_node.getElementName().compare(Context::GetName())) 70 WARNING("Le noeud est mal nommé mais sera traité comme un context !"); 71 72 if (!(_node.goToChildElement())) 73 WARNING("Le context ne contient pas d'enfant !"); 74 else 75 { 76 do { // Parcours des contexts pour traitement. 77 78 string name = _node.getElementName(); 79 attributes.clear(); 80 _node.getAttributes(attributes); 81 82 if (attributes.end() != attributes.find("id")) 83 { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); } 84 85 if (name.compare(FieldDefinition::GetDefName()) == 0) // Parsing définition des champs. 86 { fieldDef = CreateInstanceAndParse<FieldDefinition>(attributes, _node, "field_definition"); continue; } 87 if (name.compare(FileDefinition::GetDefName()) == 0) // Parsing définition des fichiers. 88 { fileDef = CreateInstanceAndParse<FileDefinition>(attributes, _node, "file_definition"); continue; } 89 90 if (name.compare("axis_definition") == 0) 91 { // Parsing pour la définition des axes. 92 INFO("Le parsing des définitions d'axes n'est pas encore implémenté"); 93 //axisDef = CreateInstance<AxisDefinition>(attributes, _node, "axis_definition"); 94 continue; 95 } 96 97 if (name.compare("grid_definition") == 0) 98 { // Parsing pour la définition des grilles. 99 INFO("Le parsing des définitions de grilles n'est pas encore implémenté"); 100 //gridDef = CreateInstance<GridDefinition>(attributes, _node, "grid_definition"); 101 continue; 102 } 103 104 WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !"); 105 106 } while (_node.goToNextElement()); 107 108 _node.goToParentElement(); // Retour au parent 109 } 110 111 return; 112 } 113 114 static string GetName(void) {return ("context"); } 115 116 virtual bool hasChild(void) const 117 { return ((fieldDef != NULL) or (fileDef != NULL) /* or (axisDef != NULL) or (gridDef != NULL) */); } 118 virtual void printChild(ostream& out) const 119 { 120 if(fieldDef != NULL) out << *(FieldGroup*)fieldDef << std::endl; 121 if(fileDef != NULL) out << *(FileGroup*) fileDef << std::endl; 122 //if(axisDef != NULL) out << *(AxisDefinition*)axisDef << std::endl; 123 //if(gridDef != NULL) out << *(GridDefinition*)gridDef << std::endl; 124 } 125 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 42 126 { 43 127 // Résolution des héritages descendants pour chacun des groupes de définitions. 44 128 if(fieldDef != NULL) fieldDef->resolveDescInheritance(); 45 if(fileDef != NULL) fileDef->resolveDescInheritance(); 129 if(fileDef != NULL) fileDef ->resolveDescInheritance(); 130 //if(axisDef != NULL) axisDef ->resolveDescInheritance(); 131 //if(gridDef != NULL) gridDef ->resolveDescInheritance(); 46 132 } 47 48 void parse (XMLNode& _node)49 {50 THashAttributes attributes;51 52 /// PARSING POUR GESTION DES ENFANTS53 if (_node.getElementName().compare(string("context")))54 WARNING("Le noeud est mal nommé mais sera traité comme un context !");55 56 if (!(_node.goToChildElement()))57 WARNING("Le context ne contient pas d'enfant !");58 else59 {60 //////////////////////////////////////61 do { // Parcours des contexts pour traitement.62 63 string name = _node.getElementName();64 attributes.clear();65 _node.getAttributes(attributes);66 67 if (attributes.end() != attributes.find("id"))68 { WARNING("Le noeud de définition possÚde un identifiant, ce dernier ne sera pas pris en compte lors du traitement !"); }69 70 if (name.compare("field_definition") == 0)71 { // Parsing pour la définition des champs.72 73 if (FieldDefinition::HasObject("field_definition"))74 WARNING("Le context possÚde déjà un noeud de définition de champs, le dernier défini complétera le premier !");75 76 fieldDef = (FieldDefinition*)&FieldDefinition::CreateObject("field_definition"); // << Conversion possible car la classe Field n'a pas de propriétés.77 fieldDef->parse(_node);78 133 79 continue;80 }81 else if (name.compare("file_definition") == 0)82 { // Parsing pour la définition des fichiers.83 84 if (FileDefinition::HasObject("file_definition"))85 WARNING("Le context possÚde déjà un noeud de définition de fichiers, le dernier défini complétera le premier !");86 87 fileDef = (FileDefinition*)&FileDefinition::CreateObject("file_definition"); // << Conversion possible car la classe Field n'a pas de propriétés.88 fileDef->parse(_node);89 90 continue;91 }92 else if (name.compare("axis_definition") == 0)93 { // Parsing pour la définition des axes.94 INFO("Le parsing des définitions d'axes n'est pas encore implémenté");95 }96 else if (name.compare("grid_definition") == 0)97 { // Parsing pour la définition des grilles.98 INFO("Le parsing des définitions de grilles n'est pas encore implémenté");99 }100 else101 WARNING("La définition est invalide, seules les champs, grilles, axes et fichiers peuvent être définis !");102 103 104 // Traitement file, grid et axis à compléter.105 } while (_node.goToNextElement());106 //////////////////////////////////////107 _node.goToParentElement(); // Retour au parent108 }109 110 return;111 }112 113 const char* getName(void) const {return ("Context"); }114 115 134 FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } 116 135 FileDefinition* getFileDefinition(void) { return (this->fileDef); } 117 136 //AxisDefinition* getAxisDefinition(void) { return (this->axisDef); } 137 //GridDefinition* getGridDefinition(void) { return (this->gridDef); } 138 118 139 ~Context() 119 { 140 { 120 141 if(fieldDef != NULL) delete fieldDef; 121 142 if(fileDef != NULL) delete fileDef; 122 } 143 //if(axisDef != NULL) delete axisDef; 144 //if(gridDef != NULL) delete gridDef; 145 } 123 146 124 147 125 148 private: 126 149 127 150 FieldDefinition* fieldDef; 128 151 FileDefinition* fileDef; … … 130 153 GridDefinition* gridDef;*/ 131 154 132 155 133 156 }; //class Context 134 157 }// namespace XMLIOSERVER -
XMLIO_V2/dev/dev_rv/src/XMLIO/field.hpp
r106 r107 10 10 { 11 11 public: 12 12 13 13 CField(void) : ObjectTemplate<CField>(), FieldAttribut() 14 {/* Ne rien faire de plus */} 15 CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut() 16 {/* Ne rien faire de plus */} 17 18 friend ostream& operator<< (ostream& out, const CField& c) 14 {/* Ne rien faire de plus */} 15 CField(const string& _id) : ObjectTemplate<CField>(_id), FieldAttribut() 16 {/* Ne rien faire de plus */} 17 18 static string GetName(void) {return ("field"); } 19 20 void parse (XMLNode& _node) 19 21 { 20 const AttributRegistrar &ar = c; 21 out << IncIndent << "<" << c.getName() << c.printId() << ar << "/>" << DecEndl; 22 return (out); 23 } 24 25 const char* getName(void) const {return ("Field"); } 22 string name = _node.getElementName(); 23 THashAttributes attributes; 26 24 27 void parse (XMLNode& _node)28 {29 string name = _node.getElementName();30 THashAttributes attributes;31 32 25 /// PARSING GESTION DES ATTRIBUTS /// 33 _node.getAttributes(attributes); 26 _node.getAttributes(attributes); 34 27 this->setAttributes(attributes); 35 28 attributes.clear(); 36 29 37 30 /// PARSING POUR GESION DES ENFANTS 38 31 // Rien à faire. 39 40 return;41 32 } 42 43 ~CField(void) 44 { /* Ne rien faire de plus */ } 45 46 }; // class Field 47 33 34 ~CField(void) 35 { /* Ne rien faire de plus */ } 36 37 }; // class Field 38 48 39 }; // namespace XMLIOSERVER 49 40 50 41 #endif // __FIELD__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/field_attribut.hpp
r106 r107 1 1 #ifndef __FIELD_ATTRIBUT__ 2 2 #define __FIELD_ATTRIBUT__ 3 4 #include "declare_attribut.hpp"5 #include "attribut_registrar.hpp"6 3 7 4 namespace XMLIOSERVER … … 10 7 { 11 8 public : 12 9 13 10 DECLARE_ATTR(name, string) ; 14 DECLARE_ATTR(description, string) ; 11 DECLARE_ATTR(description, string) ; 15 12 DECLARE_ATTR(unit, string) ; 16 13 DECLARE_ATTR(operation, string); 17 14 18 15 DECLARE_ATTR(freq_op, int) ; 19 16 DECLARE_ATTR(level, int) ; 20 17 DECLARE_ATTR(prec, int) ; 21 18 22 19 DECLARE_ATTR(enabled, bool); 23 20 24 21 DECLARE_ATTR(axis_ref, string); 25 22 DECLARE_ATTR(grid_ref, string); 26 23 DECLARE_ATTR(zoom_ref, string); 27 24 DECLARE_ATTR(field_ref, string); 28 25 29 26 FieldAttribut(void) : AttributRegistrar() 30 27 { registerAllAttributes(); } 31 28 32 29 private : 33 30 34 31 void registerAllAttributes(void) 35 32 { 36 33 RegisterAttribut(&name) ; 37 RegisterAttribut(&description) ; 34 RegisterAttribut(&description) ; 38 35 RegisterAttribut(&unit) ; 39 36 RegisterAttribut(&operation); 40 37 41 38 RegisterAttribut(&freq_op) ; 42 39 RegisterAttribut(&level) ; 43 40 RegisterAttribut(&prec) ; 44 41 RegisterAttribut(&enabled); 45 42 46 43 RegisterAttribut(&axis_ref); 47 44 RegisterAttribut(&grid_ref); … … 49 46 RegisterAttribut(&field_ref); 50 47 } 51 48 52 49 } ; // class FieldAttribut 53 50 54 51 }// namespace XMLIOSERVER 55 52 -
XMLIO_V2/dev/dev_rv/src/XMLIO/field_group.hpp
r106 r107 3 3 4 4 namespace XMLIOSERVER 5 { 5 { 6 6 class FieldGroup : public GroupTemplate<CField, FieldAttribut> 7 7 { 8 8 public: 9 9 10 10 FieldGroup(void) : GroupTemplate<CField, FieldAttribut>() 11 {/* Ne rien faire de plus */} 11 {/* Ne rien faire de plus */} 12 12 FieldGroup(const string& _id) : GroupTemplate<CField, FieldAttribut>(_id) 13 13 {/* Ne rien faire de plus */} 14 15 const char* getName(void) const {return ("Field_Group"); } 16 17 18 /// TODO A remonter dans l'arbre des héritages 19 friend ostream& operator<< (ostream& out, const FieldGroup& c) 20 { 21 const AttributRegistrar &ar = c; 22 out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl; 23 24 // Ecriture des sous-groupes. 25 for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) 26 out << *((FieldGroup*)c.groupList.getVector()[i]) << std::endl; 27 28 // Ecriture des enfants. 29 for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) 30 out << *(c.childList.getVector()[i]) << std::endl; 31 32 out << NIndent << "</" << c.getName()<< ">" << DecEndl; 33 34 return (out); 35 } 36 37 /// TODO A remonter dans l'arbre des héritages 38 void resolveDescInheritance(const AttributRegistrar* _parent = 0) 39 { 40 const vector<CField*>& childvect = childList.getVector(); 41 const vector<GroupTemplate<CField, FieldAttribut>*>& groupvect = groupList.getVector(); 42 43 // On complÚte les propres attributs du groupe. 44 if (_parent!= NULL) addAttributes(*_parent); 45 46 for(unsigned int i = 0; i < childvect.size() ; i++) 47 // on complÚte les attributs des champs enfants 48 childvect[i] -> addAttributes(*this); 49 50 for(unsigned int i = 0; i < groupvect.size() ; i++) 51 // on complÚte les attributs des groupes de champs enfants 52 ((FieldGroup*)groupvect[i]) -> resolveDescInheritance(this); 53 } 54 14 55 15 void parse (XMLNode& _node, bool _withAttr = true) 56 16 { 57 string name = _node.getElementName(); 17 string name = _node.getElementName(); 58 18 THashAttributes attributes; 59 19 … … 61 21 if (_withAttr) 62 22 { 63 _node.getAttributes(attributes); 23 _node.getAttributes(attributes); 64 24 this->setAttributes(attributes); 65 25 66 26 if (attributes.end() != attributes.find("src")) 67 { // Si une demande d'inclusion de fichier est trouvé .27 { // Si une demande d'inclusion de fichier est trouvée. 68 28 XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 69 29 parse (_node_inc); 70 30 } 71 72 31 attributes.clear(); 73 32 } 74 33 75 34 /// PARSING POUR GESION DES ENFANTS 76 35 if (!(_node.goToChildElement())) … … 79 38 { 80 39 ////////////////////////////////////// 81 do { // Parcours des contexts pour traitement. 82 40 do { // Parcours des contexts pour traitement. 41 83 42 string name = _node.getElementName(); 84 43 attributes.clear(); 85 _node.getAttributes(attributes); 86 87 if (name.compare("field_group") == 0) 88 { // Parsing pour les groupes de champs 89 90 FieldGroup* fgroup = NULL; 91 92 if (attributes.end() != attributes.find("id")) 93 {// Si l'identifiant est défini. 94 if (FieldGroup::HasObject(attributes["id"])) 95 WARNING("Dans le context actuel, un groupe de champ du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 96 fgroup = (FieldGroup*)(&createGroup(attributes["id"])); 97 fgroup->parse(_node); 98 } 99 else 100 {// Si l'identifiant n'est pas défini. 101 fgroup = (FieldGroup*)(&createGroup()); 102 fgroup->parse(_node); 103 } 104 continue; 105 106 } 107 else if (name.compare("field") == 0) 108 { // Parsing pour les champs. 109 110 CField* field = NULL; 111 112 if (attributes.end() != attributes.find("id")) 113 {// Si l'identifiant est défini. 114 if (CField::HasObject(attributes["id"])) 115 WARNING("Dans le context actuel, un champ du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 116 field = (CField*)(&createChild(attributes["id"])); 117 field->parse(_node); 118 } 119 else 120 {// Si l'identifiant n'est pas défini. 121 field = (CField*)(&createChild()); 122 field->parse(_node); 123 } 124 continue; 125 } 126 else 127 WARNING("Un groupe de champs ne peut contenir qu'un champ ou un autre groupe de champs !"); 128 44 _node.getAttributes(attributes); 45 46 if (name.compare(FieldGroup::GetName()) == 0) 47 { createGroupAndParse<FieldGroup>(attributes, _node); continue; } 48 49 if (name.compare(CField::GetName()) == 0) 50 { createChildAndParse<CField>(attributes, _node); continue; } 51 52 WARNING("Un groupe de champs ne peut contenir qu'un champ ou un autre groupe de champs !"); 53 129 54 } while (_node.goToNextElement()); 130 55 ////////////////////////////////////// 131 _node.goToParentElement(); // Retour au parent 56 _node.goToParentElement(); // Retour au parent 132 57 } 133 134 return;135 58 } 136 137 virtual ~FieldGroup(void) 59 60 virtual ~FieldGroup(void) 138 61 {/* Ne rien faire de plus */ } 139 62 140 63 }; // class FieldGroup 141 64 142 65 typedef FieldGroup FieldDefinition ; 143 66 144 67 }; // namespace XMLIOSERVER 145 68 146 69 #endif // __FIELD_GROUP__ 147 70 -
XMLIO_V2/dev/dev_rv/src/XMLIO/file.hpp
r106 r107 6 6 7 7 namespace XMLIOSERVER 8 { 8 { 9 9 class CFile : public ObjectTemplate<CFile>, public FileAttribut 10 10 { 11 11 public: 12 12 13 13 CFile(void) : ObjectTemplate<CFile>(), FileAttribut(), vfieldGroup(NULL) 14 {/* Ne rien faire de plus */} 15 CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL) 16 {/* Ne rien faire de plus */} 17 18 friend ostream& operator<< (ostream& out, const CFile& c) 14 {/* Ne rien faire de plus */} 15 CFile(const string& _id) : ObjectTemplate<CFile>(_id), FileAttribut(), vfieldGroup(NULL) 16 {/* Ne rien faire de plus */} 17 18 static string GetName(void) { return ("file"); } 19 20 void parse (XMLNode& _node) 19 21 { 20 21 const AttributRegistrar &ar = c; 22 out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl; 23 if(c.vfieldGroup != NULL) out << *c.vfieldGroup << std::endl; 24 out << NIndent << "</" << c.getName()<< ">" << DecEndl; 25 26 return (out); 27 } 28 29 const char* getName(void) const {return ("File"); } 22 string name = _node.getElementName(); 23 THashAttributes attributes; 30 24 31 void parse (XMLNode& _node)32 {33 string name = _node.getElementName();34 THashAttributes attributes;35 36 25 /// PARSING GESTION DES ATTRIBUTS /// 37 _node.getAttributes(attributes); 26 _node.getAttributes(attributes); 38 27 this->setAttributes(attributes); 39 28 attributes.clear(); 40 41 /// PARSING POUR GESION DES ENFANTS 29 30 /// PARSING POUR GESION DES ENFANTS /// 42 31 if (_node.goToChildElement() and hasId()) 43 32 { // Si la définition du fichier intégre des champs et si le fichier est identifié. 44 45 33 _node.goToParentElement(); 46 47 vfieldGroup = (FieldGroup*)(&FieldGroup::CreateObject(getId())); 48 vfieldGroup->parse(_node, false); 49 50 } else _node.goToParentElement(); 51 52 return; 34 vfieldGroup = CreateInstanceAndParse<FieldGroup>(attributes, _node, getId().c_str(), false ); 35 } 53 36 } 54 37 38 virtual bool hasChild(void) const { return (vfieldGroup != NULL); } 39 virtual void printChild(ostream& out) const { out << *vfieldGroup << std::endl; } 40 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 41 { addAttributes(*_parent); if(vfieldGroup != NULL) vfieldGroup->resolveDescInheritance(); } 42 55 43 FieldGroup* getVirtualFieldGroup(void) { return (vfieldGroup); } 56 bool hasVirtualFieldGroup(void) { return (vfieldGroup != NULL); } 57 58 ~CFile(void) 59 { if(vfieldGroup != NULL) delete vfieldGroup; } 60 44 45 ~CFile(void) 46 { if(vfieldGroup != NULL) delete vfieldGroup; } 47 61 48 private : 62 49 63 50 FieldGroup* vfieldGroup; // FieldGroup "virtuel" 64 65 }; // class CFile 66 51 52 }; // class CFile 53 67 54 }; // namespace XMLIOSERVER 68 55 69 56 #endif // __CFILE__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/file_attribut.hpp
r106 r107 1 1 #ifndef __FILE_ATTRIBUT__ 2 2 #define __FILE_ATTRIBUT__ 3 4 #include "declare_attribut.hpp"5 #include "attribut_registrar.hpp"6 3 7 4 namespace XMLIOSERVER … … 10 7 { 11 8 public : 12 9 13 10 DECLARE_ATTR(name, string) ; 14 DECLARE_ATTR(description, string) ; 11 DECLARE_ATTR(description, string) ; 15 12 DECLARE_ATTR(output_freq, int) ; 16 DECLARE_ATTR(output_level, int) ; 13 DECLARE_ATTR(output_level, int) ; 17 14 DECLARE_ATTR(enabled, bool); 18 15 19 16 FileAttribut(void) : AttributRegistrar() 20 17 { registerAllAttributes(); } 21 18 22 19 private : 23 20 24 21 void registerAllAttributes(void) 25 22 { 26 23 RegisterAttribut(&name) ; 27 RegisterAttribut(&description) ; 24 RegisterAttribut(&description) ; 28 25 RegisterAttribut(&output_freq) ; 29 26 RegisterAttribut(&output_level) ; 30 RegisterAttribut(&enabled); 27 RegisterAttribut(&enabled); 31 28 } 32 29 33 30 } ; // class FileAttribut 34 31 35 32 }// namespace XMLIOSERVER 36 33 -
XMLIO_V2/dev/dev_rv/src/XMLIO/file_group.hpp
r106 r107 3 3 4 4 namespace XMLIOSERVER 5 { 5 { 6 6 class FileGroup : public GroupTemplate<CFile, FileAttribut> 7 7 { 8 8 public: 9 9 10 10 FileGroup(void) : GroupTemplate<CFile, FileAttribut>() 11 {/* Ne rien faire de plus */} 11 {/* Ne rien faire de plus */} 12 12 FileGroup(const string& _id) : GroupTemplate<CFile, FileAttribut>(_id) 13 13 {/* Ne rien faire de plus */} 14 15 const char* getName(void) const {return ("File_Group"); } 16 17 18 /// TODO A remonter dans l'arbre des héritages 19 friend ostream& operator<< (ostream& out, const FileGroup& c) 20 { 21 const AttributRegistrar &ar = c; 22 out << IncIndent << "<" << c.getName() << c.printId() << ar << ">" << std::endl; 23 24 // Ecriture des sous-groupes. 25 for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) 26 out << *((FileGroup*)c.groupList.getVector()[i]) << std::endl; 27 28 // Ecriture des enfants. 29 for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) 30 out << *((CFile*)c.childList.getVector()[i]) << std::endl; 31 32 out << NIndent << "</" << c.getName()<< ">" << DecEndl; 33 34 return (out); 35 } 36 37 /// TODO A remonter dans l'arbre des héritages 38 void resolveDescInheritance(const AttributRegistrar* _parent = 0) 14 15 void parse (XMLNode& _node, bool _withAttr = true) 39 16 { 40 const vector<CFile*>& childvect = childList.getVector(); 41 const vector<GroupTemplate<CFile, FileAttribut>*>& groupvect = groupList.getVector(); 42 43 // On complÚte les propres attributs du groupe. 44 if (_parent!= NULL) addAttributes(*_parent); 45 46 for(unsigned int i = 0; i < childvect.size() ; i++) 47 { // on complÚte les attributs des champs enfants. 48 childvect[i] -> addAttributes(*this); 49 if (childvect[i]->hasVirtualFieldGroup()) 50 childvect[i]->getVirtualFieldGroup()-> resolveDescInheritance(); 51 } 52 53 for(unsigned int i = 0; i < groupvect.size() ; i++) 54 // on complÚte les attributs des groupes de champs enfants. 55 ((FileGroup*)groupvect[i]) -> resolveDescInheritance(this); 56 } 57 58 void parse (XMLNode& _node) 59 { 60 string name = _node.getElementName(); 17 string name = _node.getElementName(); 61 18 THashAttributes attributes; 62 19 63 20 /// PARSING GESTION DES ATTRIBUTS /// 64 _node.getAttributes(attributes); 65 this->setAttributes(attributes); 66 67 if (attributes.end() != attributes.find("src")) 68 { // Si une demande d'inclusion de fichier est trouvé. 69 XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 70 parse (_node_inc); 21 if (_withAttr) 22 { 23 _node.getAttributes(attributes); 24 this->setAttributes(attributes); 25 26 if (attributes.end() != attributes.find("src")) 27 { // Si une demande d'inclusion de fichier est trouvée. 28 XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 29 parse (_node_inc); 30 } 31 32 attributes.clear(); 71 33 } 72 73 attributes.clear(); 74 75 /// PARSING POUR GESION DES ENFANTS 34 35 /// PARSING POUR GESION DES ENFANTS /// 76 36 if (!(_node.goToChildElement())) 77 37 WARNING("Le groupe de fichier ne contient pas d'enfant !"); … … 79 39 { 80 40 ////////////////////////////////////// 81 do { // Parcours des contexts pour traitement. 82 41 do { // Parcours des contexts pour traitement. 42 83 43 string name = _node.getElementName(); 84 44 attributes.clear(); 85 _node.getAttributes(attributes); 86 87 if (name.compare("file_group") == 0) 88 { // Parsing pour les groupes de champs 89 90 FileGroup* fgroup = NULL; 91 92 if (attributes.end() != attributes.find("id")) 93 {// Si l'identifiant est défini. 94 if (FileGroup::HasObject(attributes["id"])) 95 WARNING("Dans le context actuel, un groupe de fichier du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 96 fgroup = (FileGroup*)(&createGroup(attributes["id"])); 97 fgroup->parse(_node); 98 } 99 else 100 {// Si l'identifiant n'est pas défini. 101 fgroup = (FileGroup*)(&createGroup()); 102 fgroup->parse(_node); 103 } 104 continue; 105 106 } 107 else if (name.compare("file") == 0) 108 { // Parsing pour les champs. 109 110 CFile* file = NULL; 111 112 if (attributes.end() != attributes.find("id")) 113 {// Si l'identifiant est défini. 114 if (CFile::HasObject(attributes["id"])) 115 WARNING("Dans le context actuel, un fichier du même nom existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 116 file = (CFile*)(&createChild(attributes["id"])); 117 file->parse(_node); 118 } 119 else 120 {// Si l'identifiant n'est pas défini. 121 file = (CFile*)(&createChild()); 122 file->parse(_node); 123 } 124 continue; 125 } 126 else 127 WARNING("Un groupe de fichiers ne peut contenir qu'un fichier ou un autre groupe de fichiers !"); 128 45 _node.getAttributes(attributes); 46 47 if (name.compare(FileGroup::GetName()) == 0) 48 { createGroupAndParse<FileGroup>(attributes, _node); continue; } 49 50 if (name.compare(CFile::GetName()) == 0) 51 { createChildAndParse<CFile>(attributes, _node) ; continue; } 52 53 WARNING("Un groupe de fichiers ne peut contenir qu'un fichier ou un autre groupe de fichiers !"); 54 129 55 } while (_node.goToNextElement()); 130 56 ////////////////////////////////////// 131 _node.goToParentElement(); // Retour au parent 57 _node.goToParentElement(); // Retour au parent 132 58 } 133 134 return;135 59 } 136 137 virtual ~FileGroup(void) 60 61 virtual ~FileGroup(void) 138 62 {/* Ne rien faire de plus */ } 139 63 140 64 }; // class FileGroup 141 65 142 66 typedef FileGroup FileDefinition ; 143 67 144 68 }; // namespace XMLIOSERVER 145 69 146 70 #endif // __FILE_GROUP__ 147 71 -
XMLIO_V2/dev/dev_rv/src/XMLIO/main.f90
r79 r107 3 3 4 4 5 CALL main_c6 5 CALL main_c 6 7 7 END PROGRAM main -
XMLIO_V2/dev/dev_rv/src/XMLIO/main_cpp.cpp
r106 r107 9 9 void main_c_ (void) 10 10 { 11 12 11 try 12 { 13 13 string file("/local/XMLIOSERVER_DEV/dev_rv/test/iodef_test.xml"); 14 14 15 15 //string file("/local/XMLIOSERVER_DEV/dev_rv/iodef_test.xml"); 16 16 ifstream istr( file.c_str() , ifstream::in ); 17 17 18 18 // On commence la lecture du flux de donnée xml qui doit posséder pour racine un unique noeud nommé "simulation". 19 19 XMLNode node = XMLNode::CreateNode(istr, "simulation"); 20 20 // On parse le fichier xml noeud par noeud (ie on construit dynamiquement notre arbre d'objets). 21 XMLParser::Parse(node); 21 XMLParser::Parse(node); 22 22 23 // On résoud les héritages descendants ainsi que les héritages par référence. 23 XMLParser::ResolveInheritance();24 24 Context::ResolveInheritance(); 25 25 26 // On poursuit le traitement ... 26 27 27 28 // On écrit l'arborescence resultante du traitement sur la sortie. 28 XMLParser::ShowTree(std::clog);29 29 Context::ShowTree(std::clog); 30 30 31 /*std::clog << "Nombre de Contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 1 attendus."<< std::endl; 31 32 std::clog << "Nombre de FieldGroups listés : " << FieldGroup::GetCurrentListObject().getSize() << " contre 5 attendus."<< std::endl; 32 33 std::clog << "Description du champs votkeavt : " << Field::GetObject("votkeavt").axis_ref << " contre \"Vertical Eddy Diffusivity\" attendus."<< std::endl;*/ 33 34 34 35 36 37 ERROR(exc.displayText()); 38 39 // 40 41 42 // 43 } 35 } 36 catch(const Exception &exc) 37 { // Pour tout type d'exceptions, on note les informations sur la sortie paramétrée. 38 ERROR(exc.displayText()); 39 // On retourne le code d'erreur en fin d'application pour traitements éventuels. 40 // return (exc.code()); 41 } 42 43 // return (0); 44 } -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_container.hpp
r106 r107 1 1 #ifndef __XMLIO_CONTAINER__ 2 #define __XMLIO_CONTAINER__ 2 #define __XMLIO_CONTAINER__ 3 3 4 4 // Classes utilisées issues de Poco … … 22 22 { 23 23 public : 24 24 25 ExHashMap() : HashMap<Key, Mapped*, Hash<Key> >(), _elemList() 25 26 {/* Ne rien faire de plus */} 26 27 27 28 Mapped* operator[] (const Key& kval) throw (XMLIOUndefinedValueException) 28 { 29 { 29 30 if(!hasMappedValue(kval)) 30 31 throw XMLIOUndefinedValueException("Appel de la méthode ExHashMap::operator["+kval+"] invalide."); 31 return (find(kval)->second); 32 return (find(kval)->second); 32 33 } 33 34 34 35 bool hasMappedValue(const Key& kval) {return (find(kval) != this->end());} 35 36 const vector<Mapped*>& getVector(void) const { return (this->_elemList); } 36 37 const vector<Mapped*>& getVector(void) const { return (this->_elemList); } 37 38 38 39 size_t getVectorSize(void) const {return (this->_elemList.size());} 39 40 size_t getSize(void) const {return (this->size());} 40 41 41 42 virtual ~ExHashMap() 42 43 {/* Ne rien faire de plus */} 43 44 44 45 protected : 45 46 46 47 bool addValue(const Key& kval, Mapped* element) 47 48 { … … 50 51 return (this->addValue(element)); 51 52 } 52 53 53 54 bool addValue(Mapped* element) 54 { this->_elemList.insert(this->_elemList.end(), element); return (true); } 55 56 55 { this->_elemList.insert(this->_elemList.end(), element); return (true); } 56 57 57 58 void removeValue(const Key& kval) // Non testé 58 59 { Mapped* element = find(kval)->second; removeValue(element); this->erase(kval); } 59 60 60 61 void removeValue(const Mapped* element) // Non testé 61 62 { 62 for (int i = 0; i < this->_elemList.size(); i++) 63 for (int i = 0; i < this->_elemList.size(); i++) 63 64 if (*this->_elemList[i] == element ) 64 65 this->_elemList.erase(this->_elemList.begin()+i); 65 66 66 67 delete element; 67 68 } 68 69 private : 69 70 private : 70 71 vector<Mapped*> _elemList; 71 72 72 73 }; // class ExHashMap 73 74 74 75 ///////////////////////////////////////////////////////////// 75 76 76 77 template<class Mapped> 77 78 class StrHashMap … … 79 80 { 80 81 public : 81 82 StrHashMap() : ExHashMap<string, Mapped, Hash<string> >() 83 {/* Ne rien faire de plus */} 84 82 83 StrHashMap() : ExHashMap<string, Mapped, Hash<string> >() 84 {/* Ne rien faire de plus */} 85 85 86 bool addObject(Mapped* element) 86 87 { if(element->hasId()) return(addValue(element->getId(), element)); return(addValue(element)); } 87 88 88 89 bool removeObject(const string& kval) 89 { 90 { 90 91 if(!ExHashMap<string, Mapped, Hash<string> >::hasMappedValue(kval)) return (false); 91 ExHashMap<string, Mapped, Hash<string> >::removeValue(kval); return (true); 92 ExHashMap<string, Mapped, Hash<string> >::removeValue(kval); return (true); 92 93 } 93 94 virtual ~StrHashMap() 94 95 virtual ~StrHashMap() 95 96 {/* Ne rien faire de plus */} 96 97 97 98 }; // class StrHashMap 98 99 99 100 }; // namespace XMLIOSERVER 100 101 101 #endif // __XMLIO_CONTAINER__ 102 #endif // __XMLIO_CONTAINER__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_group_template.hpp
r106 r107 1 1 #ifndef __XMLIO_GROUP_TEMPLATE__ 2 #define __XMLIO_GROUP_TEMPLATE__ 2 #define __XMLIO_GROUP_TEMPLATE__ 3 3 4 4 namespace XMLIOSERVER … … 8 8 { 9 9 public: 10 10 11 11 GroupTemplate(void) : ObjectTemplate<GroupTemplate<T, U> >(), U(), childList(), groupList() 12 {/* Ne rien faire de plus */} 12 {/* Ne rien faire de plus */} 13 13 GroupTemplate(const string& _id) : ObjectTemplate<GroupTemplate<T, U> >(_id), U(), childList(), groupList() 14 {/* Ne rien faire de plus */} 15 14 {/* Ne rien faire de plus */} 15 16 16 /// Pour les groupes d'objets enfants /// 17 18 GroupTemplate<T, U>& createGroup(const string _id) throw (XMLIOUndefinedValueException) 17 18 static string GetName(void) {return (T::GetName().append("_group")); } 19 static string GetDefName(void) {return (T::GetName().append("_definition")); } 20 21 virtual bool hasChild(void) const { return ((getNbGroup() + getNbChild())>0); } 22 virtual void printChild(ostream& out) const 23 { 24 // Ecriture des sous-groupes. 25 for(unsigned int i = 0; i < groupList.getVector().size() ; i++) 26 out << *(groupList.getVector()[i]) << std::endl; 27 // Ecriture des enfants. 28 for(unsigned int i = 0; i < childList.getVector().size() ; i++) 29 out << *(childList.getVector()[i]) << std::endl; 30 } 31 32 virtual void resolveDescInheritance(const AttributRegistrar* _parent = 0) 33 { 34 const vector<T*>& childvect = childList.getVector(); 35 const vector<GroupTemplate<T, U>*>& groupvect = groupList.getVector(); 36 37 // On complÚte les propres attributs du groupe. 38 if (_parent!= NULL) AttributRegistrar::addAttributes(*_parent); 39 40 for(unsigned int i = 0; i < childvect.size() ; i++) 41 // on complÚte les attributs des enfants. 42 childvect[i] -> resolveDescInheritance(this); 43 for(unsigned int i = 0; i < groupvect.size() ; i++) 44 // on complÚte les attributs des groupes enfants. 45 groupvect[i] -> resolveDescInheritance(this); 46 } 47 48 GroupTemplate<T, U>& createGroup(const string _id) throw (XMLIOUndefinedValueException) 19 49 { 20 50 GroupTemplate<T, U> &obj = GroupTemplate<T, U>::CreateObject(_id); 21 51 groupList.addObject(&obj); 22 52 23 53 return (GroupTemplate<T, U>::GetObject(_id)); 24 54 } 25 26 XML::XMLNode getNodeIncludedFile(const string& path, const string& _rootName) 27 { 28 ifstream istr( path.c_str() , ifstream::in ); 29 return XML::XMLNode::CreateNode(istr, _rootName); 30 } 31 55 32 56 GroupTemplate<T, U>& createGroup(void) 33 57 { 34 58 GroupTemplate<T, U>& obj = GroupTemplate<T, U>::CreateObject(); 35 59 groupList.addObject(&obj); 36 60 37 61 return (obj); 38 62 } 39 63 40 64 GroupTemplate<T, U>& getGroup(const string _id) throw (XMLIOUndefinedValueException) { return (*groupList[_id]); } 41 65 bool hasGroup(const string _id) { return (groupList.hasMappedValue(_id)); } 42 66 43 67 const StrHashMap<GroupTemplate<T, U>* >& getGroupList(void) { return (groupList); } 44 68 45 69 size_t getNbGroup() const {return (groupList.getVectorSize()); } 46 70 47 71 /// Pour les objets enfants /// 48 49 T& createChild(const string _id) throw (XMLIOUndefinedValueException) 72 73 T& createChild(const string _id) throw (XMLIOUndefinedValueException) 50 74 { 51 75 T& obj = ObjectTemplate<T>::CreateObject(_id); … … 53 77 return (obj); 54 78 } 55 79 56 80 T& createChild(void) 57 81 { 58 82 T& obj = ObjectTemplate<T>::CreateObject(); 59 childList.addObject(&obj); 83 childList.addObject(&obj); 60 84 return (obj); 61 } 62 85 } 86 63 87 T& getChild(const string _id) throw (XMLIOUndefinedValueException) { return (*childList[_id]); } 64 88 bool hasChild(const string _id) { return (childList.hasMappedValue(_id)); } 65 89 66 90 const StrHashMap<T*>& getCurrentListChild(void) { return (childList); } 67 91 68 92 size_t getNbChild() const {return (childList.getVectorSize()); } 69 70 93 71 94 virtual ~GroupTemplate() 72 95 { … … 76 99 delete groupList.getVector()[i]; 77 100 } 78 101 79 102 protected: 80 103 104 template <class V> V* createGroupAndParse(THashAttributes& attributes, XMLNode& _node) 105 { 106 V* instance_ptr = NULL; 107 if (attributes.end() != attributes.find("id")) 108 {// Si l'identifiant est défini. 109 if (V::HasObject(attributes["id"])) 110 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 111 instance_ptr = (V*)(&createGroup(attributes["id"])); 112 instance_ptr->parse(_node); 113 } 114 else 115 {// Si l'identifiant n'est pas défini. 116 instance_ptr = (V*)(&createGroup()); 117 instance_ptr->parse(_node); 118 } 119 return (instance_ptr); 120 } 121 122 template <class V> V* createChildAndParse(THashAttributes& attributes, XMLNode& _node) 123 { 124 V* instance_ptr = NULL; 125 if (attributes.end() != attributes.find("id")) 126 {// Si l'identifiant est défini. 127 if (V::HasObject(attributes["id"])) 128 WARNING("Dans le context actuel, une instance de type "+V::GetName()+" nommée "+attributes["id"]+" existe déjà , le second fera référence au premier par défaut !"); // TODO TODO 129 instance_ptr = (V*)(&createChild(attributes["id"])); 130 instance_ptr->parse(_node); 131 } 132 else 133 {// Si l'identifiant n'est pas défini. 134 instance_ptr = (V*)(&createChild()); 135 instance_ptr->parse(_node); 136 } 137 return (instance_ptr); 138 } 139 81 140 StrHashMap<T> childList; 82 141 StrHashMap<GroupTemplate<T, U> > groupList; 83 142 84 143 }; // class GroupTemplate 85 86 87 144 145 146 88 147 }// namespace XMLIOSERVER 89 148 -
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__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_node.hpp
r106 r107 1 1 #ifndef __XMLIO_XML_NODE__ 2 #define __XMLIO_XML_NODE__ 2 #define __XMLIO_XML_NODE__ 3 3 4 4 // Entêtes Poco DOM … … 44 44 namespace XML 45 45 { 46 46 47 47 typedef HashMap<string, string> THashAttributes; 48 49 // TODO Mettre des auto_ptr ici car gestion de la mémoire lamentable sans. 50 typedef AutoPtr<Document> PDocument; 51 typedef Node* PNode; 52 48 53 49 class XMLNode 54 50 { 55 51 public : 56 57 XMLNode(const string& _rootName) : rootName(_rootName) 58 { /* Ne rien faire de plus */} 52 53 XMLNode(const string& _rootName) : rootName(_rootName) 54 { /* Ne rien faire de plus */} 59 55 60 56 static XMLNode CreateNode(istream& _istr, const string& _rootName = string("simulation")) … … 65 61 InputSource src(_istr); 66 62 DOMParser parser; 67 63 68 64 // On parse la source XML et on vérifie que le premier noeud (racine) est du type "Element" 69 65 // ... et à pour valeur la chaîne rootName. … … 72 68 { node.setCNode(node.pDoc->documentElement()); } 73 69 else 74 { 75 ostringstream oss; 76 oss << "L'élément racine doit avoir pour valeur <" << _rootName << "> (\"" << (node.pDoc->documentElement()->nodeName()) <<"\" lue)"; 77 throw XMLParsingException(oss.str()); 78 } 70 throw XMLParsingException("L'élément racine doit avoir pour valeur <" + _rootName + "> (\"" + (node.pDoc->documentElement()->nodeName()) + "\" lue)"); 79 71 } 80 72 else 81 73 throw XMLIOStreamException("Impossible de lire le flux en entrée pour le parsing XML !"); 82 74 83 75 return (node); 84 76 } 85 77 86 78 string getElementName(void) const {return (this->getCNode()->nodeName());} 87 88 bool goToNextElement(void) 79 80 bool goToNextElement(void) 89 81 { 90 PNodenextElement = this->getCNode()->nextSibling();91 82 Node* nextElement = this->getCNode()->nextSibling(); 83 92 84 // On parcourt la liste des "siblings" jusqu'à trouver un élément quelconque. 93 85 for(; ; nextElement = nextElement->nextSibling()) … … 97 89 this->setCNode(nextElement) ; 98 90 return (true); 99 } 91 } 100 92 return (false); 101 93 } 102 94 103 95 bool goToChildElement(void) 104 96 { 105 PNodenextElement = this->getCNode()->firstChild();106 97 Node* nextElement = this->getCNode()->firstChild(); 98 107 99 // On parcourt la liste des enfants jusqu'à trouver un élément quelconque. 108 100 if (!IsPtrNull(nextElement)) … … 117 109 return (false); 118 110 } 119 111 120 112 return (false); 121 113 } 122 114 123 115 bool goToParentElement(void) 124 { 116 { 125 117 // Pas de retour au parent si on est à la racine. 126 118 if (!(this->getElementName().compare(rootName))) return (false); … … 128 120 return (true); 129 121 } 130 122 131 123 bool getAttributes(THashAttributes& attributes) const 132 124 { 133 125 134 126 if(!this->getCNode()->hasAttributes()) return (false); 135 127 AutoPtr<NamedNodeMap> map = this->getCNode()->attributes(); 136 128 137 129 for(unsigned int i = 0; i< map->length(); i++) 138 130 attributes[map->item(i)->nodeName()] = map->item(i)->nodeValue(); … … 140 132 return (true); 141 133 } 142 143 ~XMLNode() 134 135 ~XMLNode() 144 136 { /* Ne rien faire de plus */ } 145 137 146 138 protected : 147 148 PNodegetCNode(void) const {return (this->cNode); }149 void setCNode( PNodeother) { this->cNode = other; }150 151 static bool IsPtrNull( PNodeptr) {return (ptr==NULL);}152 139 140 Node* getCNode(void) const {return (this->cNode); } 141 void setCNode(Node* other) { this->cNode = other; } 142 143 static bool IsPtrNull(Node* ptr) {return (ptr==NULL);} 144 153 145 private : 154 PDocument pDoc;155 PNodecNode;156 157 string rootName; 158 146 AutoPtr<Document> pDoc; 147 Node* cNode; 148 149 string rootName; 150 159 151 };// class XMLNode 160 152 161 153 }; // namespace XML 162 154 … … 164 156 165 157 166 #endif // __XMLIO_XML_NODE__ 158 #endif // __XMLIO_XML_NODE__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_parser.hpp
r106 r107 1 1 #ifndef __XMLIO_XML_PARSER__ 2 #define __XMLIO_XML_PARSER__ 2 #define __XMLIO_XML_PARSER__ 3 3 4 4 #include <stdlib.h> … … 10 10 { 11 11 namespace XML 12 { 12 { 13 13 using XMLIOSERVER::Context; 14 14 15 15 class XMLParser 16 16 { 17 public : 18 17 public : 18 19 19 static void Parse(XMLNode& _node) 20 20 { 21 21 THashAttributes attributes; 22 22 23 23 _node.goToChildElement(); // On se place sur le premier élément enfant du noeud racine. 24 atexit (& XMLParser::FreeMemory); // Pour supprimer la mémoire liée à l'allocation dynamique en fin d'exécution du programme.24 atexit (&Context::FreeMemory); // Pour supprimer la mémoire liée à l'allocation dynamique en fin d'exécution du programme. 25 25 26 27 do { 26 do { 28 27 // Traitement de l'identifiant 29 28 _node.getAttributes(attributes); 30 29 31 30 if (attributes.end() == attributes.find("id")) 32 31 { WARNING("Le context ne sera pas traité car il n'est pas identifié !"); continue; } 33 32 34 33 if( Context::HasObject(attributes["id"])) 35 34 { WARNING("Le context ne sera pas traité car il existe déjà un autre context possédant le même nom !"); continue; } 36 35 37 36 Context::SetCurrentContext(attributes["id"]); 38 37 Context& context = Context::CreateObject(attributes["id"]); 39 38 40 39 context.parse(_node); 41 40 attributes.clear(); 42 43 } while (_node.goToNextElement()); 41 42 } while (_node.goToNextElement()); 44 43 } 45 46 static void ResolveInheritance(void) 47 { 48 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 49 50 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 51 { 52 string& id = (*it).first; 53 StrHashMap<Context>& sc = (*it).second; 54 55 // Résolution des héritages des descendands (cà d des héritages de groupes) pour chacun des contextes. 56 sc[id]->resolveDescInheritance(); 57 } 58 } 59 60 static void ShowTree(ostream& os = std::clog) 61 { 62 clog << "<?xml version=\"1.0\"?>" << std::endl; 63 clog << "<Simulation>" << std::endl; 64 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 65 66 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 67 { 68 string& id = (*it).first; 69 StrHashMap<Context>& sc = (*it).second; 70 71 // On sort chacun des contextes successivement. 72 clog << *sc[id] << std::endl; 73 } 74 clog << "</Simulation>" << std::endl ; 75 } 76 77 static void FreeMemory(void) 78 { 79 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 80 81 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 82 { 83 string& id = (*it).first; 84 StrHashMap<Context>& sc = (*it).second; 85 Context::SetCurrentContext(id); 86 delete sc[id]; 87 } 88 } 89 90 }; // class XMLParser 44 }; // class XMLParser 91 45 }; // namespace XML 92 46 … … 94 48 95 49 96 #endif // __XMLIO_XML_PARSER__ 50 #endif // __XMLIO_XML_PARSER__
Note: See TracChangeset
for help on using the changeset viewer.