Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCK / HexXmlWriter.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 400ba2b..a1e08af
@@ -1,12 +1,12 @@
 
 // C++ : Ecriture en XML
 
-// Copyright (C) 2009-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2024  CEA, EDF
 //
 // 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
@@ -33,38 +33,69 @@ XmlWriter::XmlWriter  ()
    xml_level = 0;
    xml_pos   = 0;
    on_file   = true;
+   xml_mode  = InaStudy;
 }
-// ========================================================= openXml 
-int XmlWriter::openXml (cpchar nomfic)
+// ========================================================= setStream
+int XmlWriter::setStream ()
 {
-   xml_level  = 0;
-   xml_pos    = 0;
-   xml_buffer = "";
-   xml_file   = stdout;
-   on_file    = false;
+   xml_mode  = InaStream;
+   xml_file  = NULL;
+   on_file   = false;
+
+   return HOK;
+}
+// ========================================================= setFile
+int XmlWriter::setFile (pfile afile)
+{
+   xml_mode  = InaStudy;
+   xml_file  = afile;
+   on_file   = true;
 
-   if (nomfic != NULL)
+   if (xml_file==NULL)
       {
-      on_file   = true;
-      bool suff = true;
-      int  pext = strlen (nomfic) - 4;
-      if (pext > 0)
-         {
-         string sext = &nomfic[pext];
-         set_minus (sext);
-         suff = sext != ".xml";
-         }
-      string fname = nomfic;
-      if (suff) 
-         fname   += ".xml";
-      xml_file = fopen (fname.c_str(), "w");
-      if (xml_file==NULL)
-         {
-         xml_file = stdout;
-         return HERR;
-         }
+      xml_file = stdout;
+      xml_mode  = InaStream;
+      return HERR;
       }
 
+   return HOK;
+}
+// ========================================================= setFileName 
+int XmlWriter::setFileName (cpchar nomfic)
+{
+   xml_mode  = InaFile;
+   xml_file  = stdout;
+   on_file   = true;
+
+   bool suff = true;
+   int  pext = strlen (nomfic) - 4;
+   if (pext > 0)
+      {
+      std::string sext = &nomfic[pext];
+      set_minus (sext);
+      suff = sext != ".xml";
+      }
+
+   std::string fname = nomfic;
+   if (suff) 
+      fname   += ".xml";
+
+   xml_file = fopen (fname.c_str(), "w");
+   if (xml_file==NULL)
+      {
+      xml_file = stdout;
+      return HERR;
+      }
+
+   return HOK;
+}
+// ========================================================= startXml 
+int XmlWriter::startXml ()
+{
+   xml_level  = 0;
+   xml_pos    = 0;
+   xml_buffer = "";
+
    ecrire ("<?xml version='1.0'?>");
    return HOK;
 }
@@ -74,10 +105,11 @@ void XmlWriter::closeXml ()
    while (NOT pile_mark.empty())
        closeMark ();
 
-   if (xml_file!=stdout)
+   if (xml_mode == InaFile && xml_file!=stdout)
+      {
       fclose (xml_file);
-
-   xml_file = stdout;
+      xml_file = stdout;
+      }
 }
 // ========================================================= addMark 
 void XmlWriter::addMark (cpchar balise, bool jump)
@@ -104,7 +136,7 @@ void XmlWriter::endMark ()
 void XmlWriter::openMark (cpchar balise)
 {
    jumpLine ();
-   string mot = "<";
+   std::string mot = "<";
    mot +=  balise;
    ecrire (mot);
 
@@ -115,8 +147,8 @@ void XmlWriter::openMark (cpchar balise)
 // ========================================================= closeMark
 void XmlWriter::closeMark (bool jump)
 {
-   string balise = pile_mark.top ();
-   string mot    = "</";
+   std::string balise = pile_mark.top ();
+   std::string mot    = "</";
    int    etat   = pile_etat.top ();
 
    xml_level --;
@@ -145,7 +177,7 @@ void XmlWriter::jumpLine ()
    xml_pos = xml_level * xml_decal;
    if (xml_pos > 0)
       {
-      string  space (xml_pos, ' ');
+      std::string  space (xml_pos, ' ');
       addMot (space.c_str());
       }
 }
@@ -175,7 +207,7 @@ void XmlWriter::alaLigne (bool force)
 // ========================================================= addAttribute 
 void XmlWriter::addAttribute (cpchar cle, cpchar valeur)
 {
-   string phrase = " ";
+   std::string phrase = " ";
    phrase += cle;
    phrase += " = \"";
    phrase += valeur;