Salome HOME
5afcbdbb187eed53d67263cfc37e2e09af0c11cb
[modules/hexablock.git] / src / HEXABLOCK / HexXmlWriter.hxx
1
2 // Class : Ecriture d'un fichier XML
3 //
4 #ifndef __XML_WRITER_H
5 #define __XML_WRITER_H
6
7 #include "hexa_base.hxx"
8 #include <stack>
9 #include <vector>
10
11 BEGIN_NAMESPACE_HEXA
12
13 class XmlWriter 
14 {
15 public :
16    XmlWriter ();
17   ~XmlWriter ()    { closeXml () ; }
18
19    int  openXml  (string& nom) { return openXml (nom.c_str()); }
20    int  openXml  (cpchar nom);
21    void closeXml ();
22
23    void openMark  (cpchar balise);                 // <Balise .. 
24    void addMark   (cpchar balise, bool jump=true); // <Balise> + eol
25    void closeMark (bool jump=false);               // </Balise> ou  />
26    void endMark ();       //         >
27
28    void addAttribute (cpchar attrib, cpchar  valeur); // attrib="valeur"
29    void addAttribute (cpchar attrib, int     valeur);
30    void addAttribute (cpchar attrib, double  valeur);
31    void addAttribute (cpchar attrib, string& valeur);
32
33 private :
34     void jumpLine ();
35     void alaLigne (bool force=false);
36     void ecrire   (cpchar  mot);
37     void ecrire   (string& mot) { ecrire (mot.c_str()) ; }
38
39 private :
40     enum  {xml_decal=3, xml_size=80};
41     pfile  xml_file;
42     int    xml_level;
43     int    xml_pos;
44     std::stack <std::string, std::vector <std::string> >  pile_mark; 
45     std::stack <int,         std::vector <int> >          pile_etat; 
46 };
47 // ====================================================== addAttribute (I)
48 inline void XmlWriter::addAttribute (cpchar attrib, int valeur)
49 {
50    char buffer [20]; 
51    sprintf (buffer, "%d", valeur);
52    addAttribute (attrib, buffer);
53 }
54 // ====================================================== addAttribute (R)
55 inline void XmlWriter::addAttribute (cpchar attrib, double valeur)
56 {
57    char buffer [20]; 
58    sprintf (buffer, "%g", valeur);
59    addAttribute (attrib, buffer);
60 }
61 // ====================================================== addAttribute (stl)
62 inline void XmlWriter::addAttribute (cpchar attrib, string& valeur)
63 {
64    addAttribute (attrib, valeur.c_str());
65 }
66
67 END_NAMESPACE_HEXA
68 #endif