1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Class : Ecriture d'un fichier XML
22 #ifndef __XML_WRITER_H
23 #define __XML_WRITER_H
25 #include "Hex_defines.hxx"
26 #include "hexa_base.hxx"
32 class HEXABLOCKENGINE_EXPORT XmlWriter
36 ~XmlWriter () { closeXml () ; }
38 int setFileName (cpchar filename); // Un seul xml par fichier
39 int setFile (pfile afile); // Plusieurs xml par fichier
40 int setStream (); // Sauvegarde par flux
43 cpchar getXml () { return xml_buffer.c_str(); }
45 void openMark (cpchar balise); // <Balise ..
46 void addMark (cpchar balise, bool jump=true); // <Balise> + eol
47 void closeMark (bool jump=false); // </Balise> ou />
50 void addAttribute (cpchar attrib, cpchar valeur); // attrib="valeur"
51 void addAttribute (cpchar attrib, int valeur);
52 void addAttribute (cpchar attrib, double valeur);
53 void addAttribute (cpchar attrib, string& valeur);
57 void alaLigne (bool force=false);
58 void ecrire (cpchar mot);
59 void ecrire (string& mot) { ecrire (mot.c_str()) ; }
60 void addMot (cpchar mot);
63 enum {InaFile, InaStudy, InaStream} xml_mode;
64 enum {xml_decal=3, xml_size=80};
70 std::string xml_buffer;
71 std::stack <std::string, std::vector <std::string> > pile_mark;
72 std::stack <int, std::vector <int> > pile_etat;
74 // ====================================================== addAttribute (I)
75 inline void XmlWriter::addAttribute (cpchar attrib, int valeur)
78 sprintf (buffer, "%d", valeur);
79 addAttribute (attrib, buffer);
81 // ====================================================== addAttribute (R)
82 inline void XmlWriter::addAttribute (cpchar attrib, double valeur)
85 sprintf (buffer, "%g", valeur);
86 addAttribute (attrib, buffer);
88 // ====================================================== addAttribute (stl)
89 inline void XmlWriter::addAttribute (cpchar attrib, string& valeur)
91 addAttribute (attrib, valeur.c_str());
93 // ====================================================== addMot
94 inline void XmlWriter::addMot (cpchar mot)
97 fprintf (xml_file, mot);