X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FHEXABLOCK%2FHexXmlTree.cxx;h=013927af018add9397812614e752373457649567;hb=9e17eedef4be735106e6d2ea4bb51e3ce116d0e3;hp=99995dd2eea1d4cea7d233cabc6c4f721dd64a29;hpb=8681e72f844274a0c2fc2cd64bbf2451bd8db77b;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCK/HexXmlTree.cxx b/src/HEXABLOCK/HexXmlTree.cxx index 99995dd..013927a 100755 --- a/src/HEXABLOCK/HexXmlTree.cxx +++ b/src/HEXABLOCK/HexXmlTree.cxx @@ -1,12 +1,12 @@ // C++ : ParserXml -// Copyright (C) 2009-2012 CEA/DEN, EDF R&D +// Copyright (C) 2009-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,7 +26,7 @@ BEGIN_NAMESPACE_HEXA enum { HEND_FILE = -2, HEND_LINE = -1, CRLF = 13 }; -// ====================================================== Constructeur +// ====================================================== Constructeur XmlTree::XmlTree (const string& nom, XmlTree* dad) { item_name = nom; @@ -79,6 +79,23 @@ const string& XmlTree::findValue (const string& nom) } return item_vide; } +// ====================================================== findInteger +int XmlTree::findInteger (const string& nom) +{ + int val = 0; + const string chnum = findValue (nom); + if (chnum==item_vide) + return val; + + int lg = chnum.size(); + for (int nc=0 ; nc= '0' && car <= '9') + val = 10*val + car - '0'; + } + return val; +} // ====================================================== parseFile int XmlTree::parseFile (const string& ficnom) { @@ -93,7 +110,7 @@ int XmlTree::parseFile (const string& ficnom) xml_file = fopen (ficnom.c_str(), "r"); if (xml_file==NULL) { - cout << " **** Fichier XML '" << ficnom << "' inaccessible" + cout << " **** Fichier XML '" << ficnom << "' inaccessible" << endl; return HERR; } @@ -101,18 +118,19 @@ int XmlTree::parseFile (const string& ficnom) int ier = parseXml (); return ier; } -// ====================================================== parseFlow -int XmlTree::parseFlow (cpchar flux) +// ====================================================== parseStream +int XmlTree::parseStream (cpchar flux, int& posit) { fic_buffer = ""; len_buffer = 0; nro_ligne = 0; fic_pos = 1988; - xml_flow = flux; - pos_flow = 0; + xml_flow = flux; + pos_flow = posit; - int ier = parseXml (); + int ier = parseXml (); + posit = pos_flow; return ier; } // ====================================================== parseXml @@ -128,11 +146,11 @@ int XmlTree::parseXml () string nom, valeur, foo; while ((item_lu=readItem (nom)) != M_NONE) { - switch (item_lu) + switch (item_lu) { case M_BEGIN : item_lu = getItem (nom, M_IDENT); - if (etat==M_PREMS) + if (etat==M_PREMS) setName (nom); else node = node -> addChild (nom); @@ -140,21 +158,23 @@ int XmlTree::parseXml () break; case M_END : - if (etat != M_BALISE_OUVERTE) + if (etat != M_BALISE_OUVERTE) putError (" balise ouverte"); etat = M_NEUTRE; break; case M_BEGIN_CLOSE : - if (etat == M_BALISE_OUVERTE) + if (etat == M_BALISE_OUVERTE) putError (" balise ouverte"); getItem (nom, M_IDENT); getItem (foo, M_END); node = node -> getParent (); + if (node==NULL) + return HOK; break; case M_CLOSE : - if (etat != M_BALISE_OUVERTE) + if (etat != M_BALISE_OUVERTE) putError (" balise deja fermee"); node = node -> getParent (); etat = M_NEUTRE; @@ -187,7 +207,7 @@ EnumItem XmlTree::getItem (string& value, EnumItem waited) { EnumItem item = readItem (value); - if (item == waited) + if (item == waited) return item; putError ("Erreur de sequence"); return item; @@ -202,7 +222,7 @@ EnumItem XmlTree::readItem (string& value) if (fic_pos>=len_buffer) { int ier=readLine (); - if (ier==HEND_FILE) + if (ier==HEND_FILE) return M_NONE; } else @@ -232,17 +252,17 @@ EnumItem XmlTree::readItem (string& value) } else if (car=='<') { - if (ncar=='/') + if (ncar=='/') { fic_pos++; return M_BEGIN_CLOSE; } - else if (ncar=='?') + else if (ncar=='?') { fic_pos++; return M_PROLOG; } - else if (ncar=='!') + else if (ncar=='!') { fic_pos++; return M_COMMENT; @@ -288,7 +308,7 @@ int XmlTree::goTo (cpchar ouca) pos = 0; else if (pos 0) @@ -357,7 +377,7 @@ int XmlTree::readLine () xml_ended = true; ier = HOK; } - else + else { xml_ended = true; ier = HEND_FILE; @@ -369,7 +389,7 @@ int XmlTree::readLine () void XmlTree::putError (cpchar mess) { printf (" ***** Erreur : %s\n", mess); - printf (" +++ Derniere ligne lue : nro %d, %deme caractere\n", + printf (" +++ Derniere ligne lue : nro %d, %deme caractere\n", nro_ligne, fic_pos); printf ("%s\n", fic_buffer.c_str()); // exit (102); @@ -401,8 +421,8 @@ void XmlTree::dump (int niveau) for (int nc=0 ; nc