Changeset 104
- Timestamp:
- 06/07/10 18:34:17 (13 years ago)
- Location:
- XMLIO_V2/dev/dev_rv/src/XMLIO
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut.hpp
r98 r104 38 38 bool hasValue ; 39 39 Ctype value ; 40 41 virtual bool _hasValue() {return hasValue;} 40 42 41 43 virtual const char * getName(void) const = 0 ; … … 74 76 return value ; 75 77 } 78 79 virtual void assignValue(const BaseAttribut* _ba) 80 { value = ((Attribut*)_ba) -> value; hasValue = true; } 76 81 77 82 virtual ostream& print(ostream & o) const 78 { 79 o<<"Attribut : "<<getName()<<" ---->" ; 80 if (hasValue) o<< boolalpha <<" value = "<< value ; 81 else o<< "/" ; 82 return o ; 83 } 83 { if (hasValue) o << " " << getName() << "=\"" << boolalpha << value << "\"" ; return o ; } 84 84 85 85 virtual void setValue(const Ctype & value_) 86 86 { hasValue=true ; value=value_ ; } 87 87 88 88 virtual void getValue(Ctype & value_) const 89 89 { -
XMLIO_V2/dev/dev_rv/src/XMLIO/attribut_registrar.hpp
r98 r104 33 33 } 34 34 } 35 36 friend ostream& operator<< (ostream& out, const AttributRegistrar& c) 37 { out << c.toString(); return (out);} 38 39 protected : 40 41 string toString(void) const 42 { 43 ostringstream st("A réimplémenter"); 44 // A compléter 45 return (st.str()); 46 } 47 35 48 36 public : 49 37 … … 51 39 {/* Ne rien faire de plus */} 52 40 53 pr ivate:41 protected : 54 42 StrHashMap<BaseAttribut> attrList; 55 43 -
XMLIO_V2/dev/dev_rv/src/XMLIO/base_attribut.hpp
r98 r104 6 6 7 7 8 using XMLIOSERVER::XMLIOIncompatib eTypeException;8 using XMLIOSERVER::XMLIOIncompatibleTypeException; 9 9 10 10 namespace XMLIOSERVER … … 12 12 class BaseAttribut 13 13 { 14 public:14 public: 15 15 16 virtual const char * getName(void) const = 0 ; 17 18 virtual ostream & print(ostream& o) const = 0 ; 16 virtual const char * getName(void) const = 0 ; 17 virtual ostream & print(ostream& o) const = 0 ; 19 18 20 friend ostream& operator <<(ostream& o,const BaseAttribut& Attr) 21 {return Attr.print(o) ; } 19 friend ostream& operator <<(ostream& o,const BaseAttribut& Attr) 20 {return Attr.print(o) ; } 21 22 virtual void assignValue(const BaseAttribut*) = 0; 22 23 23 virtual const char * getId(void) {return getName();} ;24 bool hasId(void){return (true);}24 virtual const char * getId(void) {return getName();} ; 25 bool hasId(void){return (true);} 25 26 26 virtual void setFromString(const std::string str) = 0; 27 virtual void setFromString(const std::string str) = 0; 28 29 #define SETTER_AND_GETTER(TYPE) \ 30 virtual void setValue(const TYPE & value) { error_set() ; }\ 31 virtual void setValue(const Array<TYPE,1>& value) { error_set() ; }\ 32 virtual void setValue(const Array<TYPE,2>& value) { error_set() ; }\ 33 virtual void setValue(const Array<TYPE,3>& value) { error_set() ; }\ 34 virtual void getValue(TYPE & value) const { error_get() ; }\ 35 virtual void getValue(Array<TYPE,1>& value) const { error_get() ; }\ 36 virtual void getValue(Array<TYPE,2>& value) const { error_get() ; }\ 37 virtual void getValue(Array<TYPE,3>& value) const { error_get() ; } 38 39 SETTER_AND_GETTER(int) 40 SETTER_AND_GETTER(bool) 41 SETTER_AND_GETTER(double) 42 SETTER_AND_GETTER(char) 43 SETTER_AND_GETTER(string) 27 44 28 virtual void setValue(const int & value) { error_set() ; } 29 virtual void setValue(const Array<int,1>& value) { error_set() ; } 30 virtual void setValue(const Array<int,2>& value) { error_set() ; } 31 virtual void setValue(const Array<int,3>& value) { error_set() ; } 45 #undef SETTER_AND_GETTER 46 47 48 virtual bool _hasValue() = 0; 49 50 static void error_set(void) 51 { throw XMLIOIncompatibleTypeException("BaseAttribut::set<type> > Setting value type is incompatible with attribut type"); } 52 53 static void error_get(void) 54 { throw XMLIOIncompatibleTypeException("BaseAttribut::set<type> >Getting value type is incompatible with attribut type"); } 32 55 33 virtual void setValue(const double & value) { error_set() ; }34 virtual void setValue(const Array<double,1>& value) { error_set() ; }35 virtual void setValue(const Array<double,2>& value) { error_set() ; }36 virtual void setValue(const Array<double,3>& value) { error_set() ; }37 38 virtual void setValue(const bool & value) { error_set() ; }39 virtual void setValue(const Array<bool,1>& value) { error_set() ; }40 virtual void setValue(const Array<bool,2>& value) { error_set() ; }41 virtual void setValue(const Array<bool,3>& value) { error_set() ; }42 43 virtual void setValue(const char * value) { error_set() ; }44 virtual void setValue(const string & value) { error_set() ; }45 virtual void setValue(const Array<string,1>& value) { error_set() ; }46 virtual void setValue(const Array<string,2>& value) { error_set() ; }47 virtual void setValue(const Array<string,3>& value) { error_set() ; }48 49 virtual void setValue(const char & value) { error_set() ; }50 virtual void setValue(const Array<char,1>& value) { error_set() ; }51 virtual void setValue(const Array<char,2>& value) { error_set() ; }52 virtual void setValue(const Array<char,3>& value) { error_set() ; }53 54 55 virtual void getValue(int & value) const { error_get() ; }56 virtual void getValue(Array<int,1>& value) const { error_get() ; }57 virtual void getValue(Array<int,2>& value) const { error_get() ; }58 virtual void getValue(Array<int,3>& value) const { error_get() ; }59 60 virtual void getValue(double & value) const { error_get() ; }61 virtual void getValue(Array<double,1>& value) const { error_get() ; }62 virtual void getValue(Array<double,2>& value) const { error_get() ; }63 virtual void getValue(Array<double,3>& value) const { error_get() ; }64 65 virtual void getValue(bool & value) const { error_get() ; }66 virtual void getValue(Array<bool,1>& value) const { error_get() ; }67 virtual void getValue(Array<bool,2>& value) const { error_get() ; }68 virtual void getValue(Array<bool,3>& value) const { error_get() ; }69 70 virtual void getValue(char * value) const { error_get() ; }71 virtual void getValue(string & value) const { error_get() ; }72 virtual void getValue(Array<string,1>& value) const { error_get() ; }73 virtual void getValue(Array<string,2>& value) const { error_get() ; }74 virtual void getValue(Array<string,3>& value) const { error_get() ; }75 76 virtual void getValue(char & value) const { error_get() ; }77 virtual void getValue(Array<char,1>& value) const { error_get() ; }78 virtual void getValue(Array<char,2>& value) const { error_get() ; }79 virtual void getValue(Array<char,3>& value) const { error_get() ; }80 81 static void error_set(void)82 {83 throw XMLIOIncompatibeTypeException("BaseAttribut::set<type> > Setting value type is incompatible with attribut type");84 }85 86 static void error_get(void)87 {88 throw XMLIOIncompatibeTypeException("BaseAttribut::set<type> >Getting value type is incompatible with attribut type");89 }90 56 }; //class BaseAttribut 91 57 } // namespace XMLIOSERVER -
XMLIO_V2/dev/dev_rv/src/XMLIO/context.hpp
r98 r104 9 9 public: 10 10 11 Context(void) : ObjectTemplate<Context>() 11 Context(void) : ObjectTemplate<Context>(), fieldDef(NULL) 12 12 {/* Ne rien faire de plus */} 13 Context(const string& _id) : ObjectTemplate<Context>(_id) 13 Context(const string& _id) : ObjectTemplate<Context>(_id), fieldDef(NULL) 14 14 {/* Ne rien faire de plus */} 15 15 … … 20 20 FieldGroup::SetContext(id); 21 21 Field::SetContext(id); 22 } 23 24 friend ostream& operator<< (ostream& out, const Context& c) 25 { 26 out << "<" << c.getName()<< " id=\"" << c.getId() << "\">"; 27 if(c.fieldDef != NULL) out << std::endl << *(FieldGroup*)c.fieldDef << std::endl; 28 out << "</" << c.getName()<< ">"; 29 return (out); 30 } 31 32 void resolveDescInheritance(void) 33 { 34 // Résolution des héritages descendants pour chacun des groupes de définitions. 35 fieldDef->resolveDescInheritance(); 22 36 } 23 37 … … 80 94 } 81 95 82 virtualconst char* getName(void) const {return ("Context"); }96 const char* getName(void) const {return ("Context"); } 83 97 84 98 FieldDefinition* getFieldDefinition(void) { return (this->fieldDef); } 85 99 86 100 ~Context() 87 { delete fieldDef; } 88 89 protected: 101 { delete fieldDef; } 102 90 103 91 104 private: -
XMLIO_V2/dev/dev_rv/src/XMLIO/field.hpp
r98 r104 10 10 { 11 11 public: 12 12 13 Field(void) : ObjectTemplate<Field>(), FieldAttribut() 13 14 {/* Ne rien faire de plus */} … … 15 16 {/* Ne rien faire de plus */} 16 17 17 void setAttributes(const THashAttributes& attr)18 friend ostream& operator<< (ostream& out, const Field& c) 18 19 { 19 for (THashAttributes::ConstIterator it = attr.begin(); it != attr.end(); it++) 20 if ((*it).first.compare(string("id"))) // Non prise en compte de l'identifiant lors de l'affectation des attributs. 21 this->setSAttribut((*it).first, (*it).second); 22 23 return; 20 out << "<" << c.getName(); 21 if(c.hasId()) out << " id=\"" << c.getId() << "\""; 22 for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; 23 out << "/>"; 24 25 return (out); 24 26 } 25 27 26 virtual const char* getName(void) const {return ("Field"); } 28 void setAttributes(const THashAttributes& _attr) 29 { 30 for (THashAttributes::ConstIterator it = _attr.begin(); it != _attr.end(); it++) 31 if ((*it).first.compare(string("id"))) 32 // Non prise en compte de l'identifiant lors de l'affectation des attributs. 33 this->setSAttribut((*it).first, (*it).second); 34 } 35 36 void addAttributes(const StrHashMap<BaseAttribut>& _pattr) 37 { 38 StrHashMap<BaseAttribut>& _lattr = getAttributList(); 39 40 //_pattr contient les attributs du parent, _lattr les attributs locaux. 41 42 for(unsigned int i = 0; i < _lattr.getVectorSize(); i++) 43 { 44 if(_lattr.getVector()[i]->_hasValue() or !_pattr.getVector()[i]->_hasValue()) continue; 45 _lattr.getVector()[i]->assignValue(_pattr.getVector()[i]); 46 } 47 } 48 49 const char* getName(void) const {return ("Field"); } 27 50 28 51 void parse (XMLNode& _node) -
XMLIO_V2/dev/dev_rv/src/XMLIO/field_attribut.hpp
r98 r104 19 19 DECLARE_ATTR(level, int) ; 20 20 DECLARE_ATTR(prec, int) ; 21 22 DECLARE_ATTR(src, string) ; // TEMPORAIRE, pour fieldgroup uniquement 23 21 24 22 DECLARE_ATTR(enabled, bool); 25 23 … … 29 27 DECLARE_ATTR(field_ref, string); 30 28 31 FieldAttribut(void) 29 FieldAttribut(void) : AttributRegistrar() 32 30 { registerAllAttributes(); } 33 31 32 private : 33 34 34 void registerAllAttributes(void) 35 35 { … … 38 38 RegisterAttribut(&unit) ; 39 39 RegisterAttribut(&operation); 40 41 RegisterAttribut(&src);// TEMPORAIRE, pour fieldgroup uniquement42 40 43 41 RegisterAttribut(&freq_op) ; -
XMLIO_V2/dev/dev_rv/src/XMLIO/field_group.hpp
r98 r104 16 16 {/* Ne rien faire de plus */} 17 17 18 void setAttributes(const THashAttributes& attr)18 void setAttributes(const THashAttributes& _attr) 19 19 { 20 for (THashAttributes::ConstIterator it = attr.begin(); it != attr.end(); it++) 21 if ((*it).first.compare(string("id"))) // Non prise en compte de l'identifiant lors de l'affectation des attributs. 20 for (THashAttributes::ConstIterator it = _attr.begin(); it != _attr.end(); it++) 21 if ((*it).first.compare(string("id"))!= 0 and (*it).first.compare(string("src"))!=0) 22 // (Au dessus) Non prise en compte de l'identifiant et de l'inclusion de fichiers externes lors de l'affectation des attributs. 22 23 this->setSAttribut((*it).first, (*it).second); 23 24 … … 25 26 } 26 27 27 virtual const char* getName(void) const {return ("FieldGroup"); } 28 const char* getName(void) const {return ("FieldGroup"); } 29 30 friend ostream& operator<< (ostream& out, const FieldGroup& c) 31 { 32 out << "<" << c.getName(); 33 if(c.hasId()) out << " id=\"" << c.getId() << "\""; 34 for(unsigned int i = 0; i < c.attrList.getVectorSize(); i++) out << *c.attrList.getVector()[i]; 35 out << ">" << std::endl; 36 37 for(unsigned int i = 0; i < c.groupList.getVector().size() ; i++) 38 out << *((FieldGroup*)c.groupList.getVector()[i]) << std::endl; 39 40 for(unsigned int i = 0; i < c.childList.getVector().size() ; i++) 41 out << *(c.childList.getVector()[i]) << std::endl; 42 43 out << "</" << c.getName()<< ">"; 44 return (out); 45 } 46 47 void addAttributes(const StrHashMap<BaseAttribut>& _pattr) 48 { 49 StrHashMap<BaseAttribut>& _lattr = getAttributList(); 50 51 //_pattr contient les attributs du parent, _lattr les attributs locaux. 52 53 for(unsigned int i = 0; i < _lattr.getVectorSize(); i++) 54 { 55 if(_lattr.getVector()[i]->_hasValue() or !_pattr.getVector()[i]->_hasValue()) continue; 56 _lattr.getVector()[i]->assignValue(_pattr.getVector()[i]); 57 } 58 } 59 60 void resolveDescInheritance(StrHashMap<BaseAttribut>* _pattr = 0) 61 { 62 const vector<Field*>& childvect = childList.getVector(); 63 const vector<GroupTemplate<Field, FieldAttribut>*>& groupvect = groupList.getVector(); 64 65 // On complÚte les propres attributs du groupe. 66 if (_pattr!= NULL) addAttributes(*_pattr); 67 68 for(unsigned int i = 0; i < childvect.size() ; i++) 69 // on complÚte les attributs des champs enfants 70 childvect[i] -> addAttributes(this->attrList); 71 72 for(unsigned int i = 0; i < groupvect.size() ; i++) 73 // on complÚte les attributs des groupes de champs enfants 74 ((FieldGroup*)groupvect[i]) -> resolveDescInheritance(&this->attrList); 75 } 28 76 29 77 void parse (XMLNode& _node) … … 31 79 string name = _node.getElementName(); 32 80 THashAttributes attributes; 33 81 34 82 /// PARSING GESTION DES ATTRIBUTS /// 35 83 _node.getAttributes(attributes); 36 84 this->setAttributes(attributes); 85 86 if (attributes.end() != attributes.find("src")) 87 { // Si une demande d'inclusion de fichier est trouvé. 88 XMLNode _node_inc = getNodeIncludedFile(attributes["src"], name); 89 parse (_node_inc); 90 } 91 37 92 attributes.clear(); 38 93 … … 58 113 if (FieldGroup::HasObject(attributes["id"])) 59 114 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 60 fgroup = (FieldGroup*)&createGroup(attributes["id"]);115 fgroup = (FieldGroup*)(&createGroup(attributes["id"])); 61 116 fgroup->parse(_node); 62 117 } 63 118 else 64 119 {// Si l'identifiant n'est pas défini. 65 fgroup = (FieldGroup*) &createGroup();120 fgroup = (FieldGroup*)(&createGroup()); 66 121 fgroup->parse(_node); 67 122 } … … 79 134 if (Field::HasObject(attributes["id"])) 80 135 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 81 field = (Field*)&createChild(attributes["id"]);136 field = (Field*)(&createChild(attributes["id"])); 82 137 field->parse(_node); 83 138 } 84 139 else 85 140 {// Si l'identifiant n'est pas défini. 86 field = (Field*) &createChild();141 field = (Field*)(&createChild()); 87 142 field->parse(_node); 88 143 } … … 102 157 103 158 virtual ~FieldGroup(void) 104 {/* Ne rien faire de plus */ }105 159 {/* Ne rien faire de plus */ } 160 106 161 }; // class FieldGroup 107 162 -
XMLIO_V2/dev/dev_rv/src/XMLIO/main.cpp
r98 r104 1 2 // g++ -Wall -std=c++0x -g -o ../../bin/XMLIOServer -I/local/tools/svn/external/include/ -L/local/tools/svn/external/lib main.cpp main_cpp.cpp -lPOCO_XML -lPOCO_Foundation -lpthread 1 3 2 4 extern "C" void main_c_(void) ; -
XMLIO_V2/dev/dev_rv/src/XMLIO/main_cpp.cpp
r98 r104 11 11 try 12 12 { 13 XMLParser::CLASS_TEST(); 14 // Code à executer ici 13 string file("/local/testsuite/iodef_test.xml"); 14 ifstream istr( file.c_str() , ifstream::in ); 15 16 // On commence la lecture du flux de donnée xml qui doit posséder pour racine un unique noeud nommé "simulation". 17 XMLNode node = XMLNode::CreateNode(istr, "simulation"); 18 // On parse le fichier xml noeud par noeud (ie on construit dynamiquement notre arbre d'objets). 19 XMLParser::Parse(node); 20 // On résoud les héritages descendants ainsi que les héritages par référence. 21 XMLParser::ResolveInheritance(); 22 23 // On poursuit le traitement ... 24 25 // On écrit l'arborescence resultante du traitement sur la sortie. 26 XMLParser::ShowTree(std::clog); 27 28 /*std::clog << "Nombre de Contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 1 attendus."<< std::endl; 29 std::clog << "Nombre de FieldGroups listés : " << FieldGroup::GetCurrentListObject().getSize() << " contre 5 attendus."<< std::endl; 30 std::clog << "Description du champs votkeavt : " << Field::GetObject("votkeavt").axis_ref << " contre \"Vertical Eddy Diffusivity\" attendus."<< std::endl;*/ 31 15 32 } 16 33 catch(const XMLIOException &exc) … … 18 35 ERROR(exc.displayText()); 19 36 // On retourne le code d'erreur en fin d'application pour traitements éventuels. 20 //return (exc.code());37 // return (exc.code()); 21 38 } 22 39 -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_container.hpp
r98 r104 34 34 bool hasMappedValue(const Key& kval) {return (find(kval) != this->end());} 35 35 36 const vector<Mapped*> getVector(void){ return (this->_elemList); }36 const vector<Mapped*>& getVector(void) const { return (this->_elemList); } 37 37 38 38 size_t getVectorSize(void) const {return (this->_elemList.size());} -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_exception.hpp
r98 r104 65 65 }; //class XMLParsingException 66 66 67 class XMLIOIncompatib eTypeException : public XMLIOException67 class XMLIOIncompatibleTypeException : public XMLIOException 68 68 { 69 69 public : 70 XMLIOIncompatib eTypeException(const std::string& _msg): XMLIOException(_msg, 1003) {}70 XMLIOIncompatibleTypeException(const std::string& _msg): XMLIOException(_msg, 1003) {} 71 71 const char* name(void) const throw() { return ("XMLIO>XMLIOIncompatibeTypeException"); } 72 72 -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_group_template.hpp
r98 r104 14 14 {/* Ne rien faire de plus */} 15 15 16 virtual const char* getName(void) const {return ("GroupTemplate"); }17 18 16 /// Pour les groupes d'objets enfants /// 19 17 … … 24 22 25 23 return (GroupTemplate<T, U>::GetObject(_id)); 24 } 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); 26 30 } 27 31 … … 75 79 protected: 76 80 77 private:78 81 StrHashMap<T> childList; 79 82 StrHashMap<GroupTemplate<T, U> > groupList; -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_logger.hpp
r98 r104 52 52 static ILogger LOGGER("xmlio.log"); 53 53 54 #define ERROR(MSG) (ILogger::GetConsoleLogger().error(MSG))55 #define WARNING(MSG) (ILogger::GetConsoleLogger().warning(MSG))56 #define INFO(MSG) (ILogger::GetConsoleLogger().information(MSG))57 // A compléter.58 59 60 61 54 /************* POUR MEMOIRE ********************** 62 55 #include <stdio.h> … … 91 84 }; // namespace XMLIOSERVER 92 85 86 #define ERROR(MSG) (XMLIOSERVER::ILogger::GetConsoleLogger().error(MSG)) 87 #define WARNING(MSG) (XMLIOSERVER::ILogger::GetConsoleLogger().warning(MSG)) 88 #define INFO(MSG) (XMLIOSERVER::ILogger::GetConsoleLogger().information(MSG)) 89 // A compléter. 90 93 91 #endif // __XMLIO_LOGGER__ -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object.hpp
r98 r104 24 24 {/* Ne rien faire de plus */} 25 25 26 const string& getId(void) throw (XMLIOUndefinedValueException)26 const string& getId(void) const throw (XMLIOUndefinedValueException) 27 27 { if (!IdDefined) throw XMLIOUndefinedValueException("Appel de la méthode AbstractObject::getId invalide."); return (id); } 28 28 … … 38 38 } 39 39 40 friend ostream& operator<< (ostream& out, const AbstractObject& c)41 { out << c.toString(); return (out);}42 43 40 virtual ~AbstractObject(void) 44 41 {/* Ne rien faire de plus */} 45 42 46 43 protected : 47 48 virtual string toString(void) const 49 { 50 ostringstream st("["); 51 st << "[" << this->getName(); 52 if (hasId()) st << " id=\"" << id << "\""; 53 st << "]" ; 54 return (st.str()); 55 } 56 57 virtual const char* getName(void) const {return ("AbstractObject"); } 44 58 45 59 46 private : -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_object_template.hpp
r98 r104 38 38 { return (*ObjectTemplate<T>::AllListObj[CurrContext][_id]); } 39 39 40 static bool HasObject(const string _id)// << Bug 41 { return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); } 40 static bool HasObject(const string _id) 41 { 42 if(ObjectTemplate<T>::AllListObj.find(CurrContext) == ObjectTemplate<T>::AllListObj.end()) return false; 43 return (ObjectTemplate<T>::AllListObj[CurrContext].hasMappedValue(_id)); 44 } 42 45 43 46 static const StrHashMap<T>& GetCurrentListObject(void) { return (AllListObj[CurrContext]); } … … 47 50 48 51 static string& GetCurrentContextId(void) { return (CurrContext); } 49 50 virtual const char* getName(void) const {return ("ObjectTemplate"); }51 52 52 53 virtual ~ObjectTemplate(void) -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_node.hpp
r98 r104 58 58 { /* Ne rien faire de plus */} 59 59 60 static XMLNode & CreateNode(XMLNode& node,istream& _istr, const string& _rootName = string("simulation"))60 static XMLNode CreateNode(istream& _istr, const string& _rootName = string("simulation")) 61 61 { 62 XMLNode node(_rootName); 62 63 if ((_istr.good())) 63 64 { // S'il est possible de lire le flux en entrée ... … … 69 70 node.pDoc = parser.parse(&src); 70 71 if (!(node.pDoc->documentElement()->nodeName().compare(_rootName))) 71 { 72 node.setCNode(node.pDoc->documentElement()); 73 node.goToChildElement(); 74 } 72 { node.setCNode(node.pDoc->documentElement()); } 75 73 else 76 74 { -
XMLIO_V2/dev/dev_rv/src/XMLIO/xmlio_xml_parser.hpp
r98 r104 1 1 #ifndef __XMLIO_XML_PARSER__ 2 2 #define __XMLIO_XML_PARSER__ 3 4 #include <stdlib.h> 3 5 4 6 // Utilisation de la STL … … 18 20 { 19 21 THashAttributes attributes; 22 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. 25 20 26 21 27 do { … … 36 42 37 43 } while (_node.goToNextElement()); 38 } 44 } 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 << "<Simulation>" << std::endl; 63 HashMap<string, StrHashMap<Context> > &AllListContext = Context::GetAllListObject(); 64 65 for (HashMap<string, StrHashMap<Context> >::Iterator it = AllListContext.begin(); it != AllListContext.end(); it++) 66 { 67 string& id = (*it).first; 68 StrHashMap<Context>& sc = (*it).second; 69 70 // On sort chacun des contextes successivement. 71 clog << *sc[id] << std::endl; 72 } 73 clog << "</Simulation>" << std::endl ; 74 } 39 75 40 76 static void FreeMemory(void) … … 46 82 string& id = (*it).first; 47 83 StrHashMap<Context>& sc = (*it).second; 48 // BUG AllListContext contient une StrHashMap<Context> liée à l'identifiant "" d'où la vérification ci-dessous. 49 if (id.size()>0) delete sc[id]; 84 delete sc[id]; 50 85 } 51 }52 53 static bool CLASS_TEST(const string& file = string("/local/testsuite/iodef_test.xml"), ostream& log = std::clog)54 {55 ifstream istr( file.c_str() , ifstream::in );56 XMLNode node("simulation");57 XMLNode::CreateNode(node, istr, "simulation");58 XMLParser::Parse(node);59 log << "Nombre de Contexts listés : " << Context::GetCurrentListObject().getSize() << " contre 1 attendus."<< std::endl;60 log << "Nombre de FieldGroups listés : " << FieldGroup::GetCurrentListObject().getSize() << " contre 5 attendus."<< std::endl;61 log << "Description du champs votkeavt : " << Field::GetObject("votkeavt").description << " contre \"Vertical Eddy Diffusivity\" attendus."<< std::endl;62 63 log << "Test XMLParser ... ok !" << std::endl;64 65 FreeMemory(); // Pour supprimer la mémoire liée à l'allocation dynamique.66 67 return (true);68 86 } 69 87
Note: See TracChangeset
for help on using the changeset viewer.