]> SALOME platform Git repositories - modules/hexablock.git/blobdiff - src/HEXABLOCK/HexXmlTree.cxx
Salome HOME
Copyright update 2022
[modules/hexablock.git] / src / HEXABLOCK / HexXmlTree.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 99995dd..95b6be2
@@ -1,12 +1,12 @@
 
 // C++ : ParserXml
 
-// Copyright (C) 2009-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2022  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,8 +26,8 @@ BEGIN_NAMESPACE_HEXA
 
 enum { HEND_FILE = -2, HEND_LINE = -1, CRLF = 13 };
 
-// ====================================================== Constructeur 
-XmlTree::XmlTree (const string& nom, XmlTree* dad)
+// ====================================================== Constructeur
+XmlTree::XmlTree (const std::string& nom, XmlTree* dad)
 {
    item_name     = nom;
    item_vide     = "";
@@ -50,7 +50,7 @@ XmlTree::~XmlTree ()
 {
 }
 // ====================================================== findChild
-XmlTree* XmlTree::findChild (const string& nom)
+XmlTree* XmlTree::findChild (const std::string& nom)
 {
    for (int nro = 0 ; nro<nbr_items ; nro++)
        {
@@ -60,7 +60,7 @@ XmlTree* XmlTree::findChild (const string& nom)
    return NULL;
 }
 // ====================================================== findAttribute
-int XmlTree::findAttribute (const string& nom)
+int XmlTree::findAttribute (const std::string& nom)
 {
    for (int nro = 0 ; nro<nbr_attributs ; nro++)
        {
@@ -70,7 +70,7 @@ int XmlTree::findAttribute (const string& nom)
    return NOTHING;
 }
 // ====================================================== findValue
-const string& XmlTree::findValue (const string& nom)
+const std::string& XmlTree::findValue (const std::string& nom)
 {
    for (int nro = 0 ; nro<nbr_attributs ; nro++)
        {
@@ -79,8 +79,25 @@ const string& XmlTree::findValue (const string& nom)
        }
    return item_vide;
 }
+// ====================================================== findInteger
+int XmlTree::findInteger (const std::string& nom)
+{
+   int   val = 0;
+   const std::string chnum = findValue (nom);
+   if (chnum==item_vide)
+      return val;
+
+   int lg = chnum.size();
+   for (int nc=0 ; nc<lg ; ++nc)
+       {
+       char car = chnum[nc];
+       if (car >= '0' && car <= '9')
+           val  = 10*val + car - '0';
+       }
+   return val;
+}
 // ====================================================== parseFile
-int XmlTree::parseFile (const string& ficnom)
+int XmlTree::parseFile (const std::string& ficnom)
 {
    fic_buffer  = "";
    len_buffer  = 0;
@@ -93,26 +110,27 @@ int XmlTree::parseFile (const string& ficnom)
    xml_file = fopen (ficnom.c_str(), "r");
    if (xml_file==NULL)
       {
-      cout << " **** Fichier XML '" << ficnom << "' inaccessible" 
-           << endl;
+      std::cout << " **** Fichier XML '" << ficnom << "' inaccessible"
+           << std::endl;
       return HERR;
       }
 
    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
@@ -125,14 +143,14 @@ int XmlTree::parseXml ()
 
    XmlTree* node = this;
    EnumItem item_lu;
-   string   nom, valeur, foo;
+   std::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;
@@ -183,17 +203,17 @@ int XmlTree::parseXml ()
    return HOK;
 }
 // ====================================================== getItem
-EnumItem XmlTree::getItem (string& value, EnumItem waited)
+EnumItem XmlTree::getItem (std::string& value, EnumItem waited)
 {
    EnumItem item = readItem (value);
 
-   if (item == waited) 
+   if (item == waited)
       return item;
    putError ("Erreur de sequence");
    return item;
 }
 // ====================================================== readItem
-EnumItem XmlTree::readItem (string& value)
+EnumItem XmlTree::readItem (std::string& value)
 {
    value  = "";
 
@@ -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;
@@ -254,7 +274,7 @@ EnumItem XmlTree::readItem (string& value)
          }
 }
 // ====================================================== getIdent
-int XmlTree::getIdent (string& ident)
+int XmlTree::getIdent (std::string& ident)
 {
    ident = "";
 
@@ -288,23 +308,23 @@ int XmlTree::goTo (cpchar ouca)
           pos = 0;
        else if (pos<nbc)
           pos++;
-       else 
+       else
           return HOK;
        }
 
    return HERR;
 }
 // ====================================================== getString
-int XmlTree::getString (string& chaine)
+int XmlTree::getString (std::string& chaine)
 {
    chaine  = "";
    int car = ' ';
 
    while ((car = getChar ()) != EOF)
        {
-       if (car=='"') 
+       if (car=='"')
           return HOK;
-       chaine.push_back (car); 
+       chaine.push_back (car);
        }
 
    return HERR;
@@ -340,7 +360,7 @@ int XmlTree::readLine ()
    int ier = HEND_LINE;
    while (ier==HEND_LINE)
          {
-         int carac = xml_flow != NULL ? xml_flow [pos_flow++] 
+         int carac = xml_flow != NULL ? xml_flow [pos_flow++]
                                      : fgetc (xml_file);
 
          if (carac==EOL || carac==CRLF)
@@ -349,7 +369,7 @@ int XmlTree::readLine ()
             }
          else if (carac!=EOF && carac!=EOS)
             {
-            fic_buffer.push_back (carac); 
+            fic_buffer.push_back (carac);
             len_buffer ++;
             }
          else if (len_buffer > 0)
@@ -357,7 +377,7 @@ int XmlTree::readLine ()
             xml_ended = true;
             ier = HOK;
             }
-         else 
+         else
             {
             xml_ended = true;
             ier = HEND_FILE;
@@ -369,13 +389,13 @@ 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);
 }
 // ====================================================== addChild
-XmlTree* XmlTree::addChild (const string& nom)
+XmlTree* XmlTree::addChild (const std::string& nom)
 {
    XmlTree* child = new XmlTree (nom, this);
    tab_items.push_back (child);
@@ -383,7 +403,7 @@ XmlTree* XmlTree::addChild (const string& nom)
    return child;
 }
 // ====================================================== addAttribut
-void XmlTree::addAttribut (const string& nom, const string& value)
+void XmlTree::addAttribut (const std::string& nom, const std::string& value)
 {
    tab_attributs.push_back (nom);
    tab_values   .push_back (value);
@@ -393,17 +413,17 @@ void XmlTree::addAttribut (const string& nom, const string& value)
 // ====================================================== dump
 void XmlTree::dump (int niveau)
 {
-   string marge = "";
+   std::string marge = "";
    for (int niv=0 ; niv<niveau ; niv++)
        marge += " | ";
 
-   cout << marge << item_name << endl;
+   std::cout << marge << item_name << std::endl;
 
    for (int nc=0 ; nc<nbr_attributs ; nc++)
        {
-       cout << marge  << " : " 
-            << tab_attributs [nc] << " = '" << tab_values [nc] 
-            << "'" << endl;
+       std::cout << marge  << " : "
+            << tab_attributs [nc] << " = '" << tab_values [nc]
+            << "'" << std::endl;
        }
 
    for (int nc=0 ; nc<nbr_items ; nc++)