X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHEXABLOCK%2FHexXmlTree.cxx;h=013927af018add9397812614e752373457649567;hb=9e17eedef4be735106e6d2ea4bb51e3ce116d0e3;hp=7c28266e2b6b286e0f1d41b221c6d11175741d99;hpb=3362101497b1bc0ded71b74c0806ac06c64d49d3;p=modules%2Fhexablock.git diff --git a/src/HEXABLOCK/HexXmlTree.cxx b/src/HEXABLOCK/HexXmlTree.cxx index 7c28266..013927a 100755 --- a/src/HEXABLOCK/HexXmlTree.cxx +++ b/src/HEXABLOCK/HexXmlTree.cxx @@ -1,26 +1,49 @@ // C++ : ParserXml +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + #include "HexXmlTree.hxx" BEGIN_NAMESPACE_HEXA enum { HEND_FILE = -2, HEND_LINE = -1, CRLF = 13 }; -// ====================================================== Constructeur +// ====================================================== Constructeur XmlTree::XmlTree (const string& nom, XmlTree* dad) { - item_name = nom; - item_vide = ""; - xml_parent = dad; - nbr_attributs = 0; - nbr_items = 0; + item_name = nom; + item_vide = ""; + xml_parent = dad; + nbr_attributs = 0; + nbr_items = 0; fic_buffer = ""; len_buffer = 0; - fic_xml = NULL; + xml_file = NULL; nro_ligne = 0; fic_pos = 1988; + + xml_flow = NULL; + pos_flow = 0; + xml_ended = true; } // ====================================================== Destructeur XmlTree::~XmlTree () @@ -56,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) { @@ -63,10 +103,40 @@ int XmlTree::parseFile (const string& ficnom) len_buffer = 0; nro_ligne = 0; fic_pos = 1988; + xml_flow = NULL; + pos_flow = 0; + xml_ended = true; - fic_xml = fopen (ficnom.c_str(), "r"); - if (fic_xml==NULL) + xml_file = fopen (ficnom.c_str(), "r"); + if (xml_file==NULL) + { + cout << " **** Fichier XML '" << ficnom << "' inaccessible" + << endl; return HERR; + } + + int ier = parseXml (); + return ier; +} +// ====================================================== parseStream +int XmlTree::parseStream (cpchar flux, int& posit) +{ + fic_buffer = ""; + len_buffer = 0; + nro_ligne = 0; + fic_pos = 1988; + + xml_flow = flux; + pos_flow = posit; + + int ier = parseXml (); + posit = pos_flow; + return ier; +} +// ====================================================== parseXml +int XmlTree::parseXml () +{ + xml_ended = false; enum EnumEtat { M_PREMS, M_BALISE_OUVERTE, M_NEUTRE }; EnumEtat etat = M_PREMS; @@ -76,11 +146,11 @@ int XmlTree::parseFile (const string& ficnom) 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); @@ -88,21 +158,23 @@ int XmlTree::parseFile (const string& ficnom) 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; @@ -135,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; @@ -150,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 @@ -180,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; @@ -209,7 +281,7 @@ int XmlTree::getIdent (string& ident) for (int nc=fic_pos-1; nc 0) + { + xml_ended = true; ier = HOK; - else + } + else + { + xml_ended = true; ier = HEND_FILE; + } } return HOK; } @@ -309,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); @@ -341,8 +421,8 @@ void XmlTree::dump (int niveau) for (int nc=0 ; nc