Changeset 96 for XMLIO_V2/dev/dev_rv/xmlio_xml_node.hpp
- Timestamp:
- 06/04/10 14:55:53 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XMLIO_V2/dev/dev_rv/xmlio_xml_node.hpp
r91 r96 9 9 #include <Poco/DOM/NamedNodeMap.h> 10 10 11 //#include <Poco/DOM/AutoPtr.h>11 #include <Poco/DOM/AutoPtr.h> 12 12 13 13 // Entêtes Poco SAX … … 38 38 using Poco::HashMap; 39 39 40 using Poco::XML::AutoPtr; 41 40 42 namespace XMLIOSERVER 41 43 { … … 46 48 47 49 // TODO Mettre des auto_ptr ici car gestion de la mémoire lamentable sans. 48 typedef Document*PDocument;49 typedef Node* 50 typedef AutoPtr<Document> PDocument; 51 typedef Node* PNode; 50 52 51 53 class XMLNode 52 54 { 53 protected :54 55 XMLNode(const string& _rootName) : rootName(_rootName) { this->cNode = NULL ; }56 57 55 public : 58 56 59 static XMLNode CreateNode(istream& _istr, const string& _rootName = string("simulation")) 57 XMLNode(const string& _rootName) : rootName(_rootName) 58 { /* Ne rien faire de plus */} 59 60 static XMLNode& CreateNode(XMLNode& node, istream& _istr, const string& _rootName = string("simulation")) 60 61 { 61 XMLNode node(_rootName);62 63 62 if ((_istr.good())) 64 63 { // S'il est possible de lire le flux en entrée ... … … 68 67 // On parse la source XML et on vérifie que le premier noeud (racine) est du type "Element" 69 68 // ... et à pour valeur la chaîne rootName. 70 PDocumentpDoc = parser.parse(&src);71 if (!( pDoc->documentElement()->nodeName().compare(_rootName)))69 node.pDoc = parser.parse(&src); 70 if (!(node.pDoc->documentElement()->nodeName().compare(_rootName))) 72 71 { 73 node. cNode = pDoc->documentElement();72 node.setCNode(node.pDoc->documentElement()); 74 73 node.goToChildElement(); 75 74 } … … 77 76 { 78 77 ostringstream oss; 79 oss << "L'élément racine doit avoir pour valeur <" << _rootName << "> (\"" << ( pDoc->documentElement()->nodeName()) <<"\" lue)";78 oss << "L'élément racine doit avoir pour valeur <" << _rootName << "> (\"" << (node.pDoc->documentElement()->nodeName()) <<"\" lue)"; 80 79 throw XMLParsingException(oss.str()); 81 80 } … … 87 86 } 88 87 89 string getElementName(void) const {return (this-> cNode->nodeName());}88 string getElementName(void) const {return (this->getCNode()->nodeName());} 90 89 91 bool goToNextElement( Node* nextElement = 0)90 bool goToNextElement(void) 92 91 { 93 nextElement = (!nextElement)? this->cNode->nextSibling() : nextElement;92 PNode nextElement = this->getCNode()->nextSibling(); 94 93 95 94 // On parcourt la liste des "siblings" jusqu'à trouver un élément quelconque. 96 95 for(; ; nextElement = nextElement->nextSibling()) 97 if (nextElement == NULL) break;98 else if (nextElement->nodeType() == 1)99 {// Si l'un des noeuds est un élément...100 this->cNode = nextElement;101 return (true);102 }103 return (false);104 96 if (IsPtrNull(nextElement)) break; 97 else if (nextElement->nodeType() == 1) 98 {// Si l'un des noeuds est un élément... 99 this->setCNode(nextElement) ; 100 return (true); 101 } 102 return (false); 103 } 105 104 106 bool goToChildElement(void) 107 { 108 // On parcourt la liste des enfants jusqu'à trouver un élément quelconque. 109 if (this->cNode->firstChild()) 110 if (this->goToNextElement(this->cNode->firstChild())) 111 return (true); 105 bool goToChildElement(void) 106 { 107 PNode nextElement = this->getCNode()->firstChild(); 108 109 // On parcourt la liste des enfants jusqu'à trouver un élément quelconque. 110 if (!IsPtrNull(nextElement)) 111 { 112 for(; ; nextElement = nextElement->nextSibling()) 113 if (IsPtrNull(nextElement)) break; 114 else if (nextElement->nodeType() == 1) 115 {// Si l'un des noeuds est un élément... 116 this->setCNode(nextElement) ; 117 return (true); 118 } 119 return (false); 120 } 112 121 113 return (false);114 122 return (false); 123 } 115 124 116 117 118 // Pas de retour au parent si on est à la racine.119 if (!(this->getElementName().compare(rootName))) return (false);120 this->cNode = this->cNode->parentNode();121 return (true);122 125 bool goToParentElement(void) 126 { 127 // Pas de retour au parent si on est à la racine. 128 if (!(this->getElementName().compare(rootName))) return (false); 129 this->setCNode(this->getCNode()->parentNode()); 130 return (true); 131 } 123 132 124 bool getAttributes(THashAttributes& attributes) const 125 { 126 if(!this->cNode->hasAttributes()) return (false); 127 NamedNodeMap* map = this->cNode->attributes(); 133 bool getAttributes(THashAttributes& attributes) const 134 { 135 136 if(!this->getCNode()->hasAttributes()) return (false); 137 AutoPtr<NamedNodeMap> map = this->getCNode()->attributes(); 128 138 129 139 for(unsigned int i = 0; i< map->length(); i++) … … 131 141 132 142 return (true); 133 143 } 134 144 135 145 ~XMLNode() 136 146 { /* Ne rien faire de plus */ } 137 147 148 protected : 149 150 PNode getCNode(void) const {return (this->cNode); } 151 void setCNode(PNode other) { this->cNode = other; } 152 153 static bool IsPtrNull(PNode ptr) {return (ptr==NULL);} 154 138 155 private : 139 156 PDocument pDoc; 140 157 PNode cNode; 158 141 159 string rootName; 142 160
Note: See TracChangeset
for help on using the changeset viewer.