Salome HOME
aca34b86284a303a409e03159d7563d64958f8f8
[modules/hexablock.git] / src / HEXABLOCK / HexXmlTree.hxx
1 // Copyright (C) 2009-2023  CEA, EDF
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Class : Ecriture d'un fichier XML
21 //
22 #ifndef __XML_TREE_H_
23 #define __XML_TREE_H_
24
25 #include "hexa_base.hxx"
26
27 #include <vector>
28
29 BEGIN_NAMESPACE_HEXA
30
31    enum EnumItem { M_NONE,  M_BEGIN, M_END, M_BEGIN_CLOSE, M_CLOSE,
32                    M_IDENT, M_EQUALS, M_STRING,
33                    M_COMMENT, M_END_COMMENT, M_PROLOG, M_END_PROLOG,
34                    M_ERROR};
35 class HexaExport XmlTree
36 {
37 public :
38    XmlTree (const std::string& name, XmlTree* dad=NULL);
39   ~XmlTree ();
40
41    int  parseFile   (const std::string& name);
42    int  parseStream (cpchar flux, int& posit);
43
44    cpchar getName  ()   { return item_name.c_str() ; }
45    int    getNbrAttributs  ()   { return nbr_attributs ; }
46    int    getNbrChildren   ()   { return nbr_items     ; }
47
48    int           findAttribute (const std::string& nom);
49    const std::string& findValue     (const std::string& nom);
50    int           findInteger   (const std::string& nom);
51
52    cpchar   getAttribute  (int nro)    { return tab_attributs [nro].c_str(); }
53    cpchar   getValue      (int nro)    { return tab_values    [nro].c_str(); }
54
55    XmlTree* findChild    (const std::string& nom);
56    XmlTree* getChild     (int nro)    { return tab_items [nro]; }
57    XmlTree* getParent    ()           { return xml_parent; }
58
59                   // ------------------------- Modifications
60
61    XmlTree* addChild    (const std::string& nom);
62    void     addAttribut (const std::string& nom, const std::string& valeur);
63    void     setName     (const std::string&  nom)   { item_name = nom; }
64    void     dump        (int niveau=0);
65
66    int      goTo        (cpchar  ouca);
67
68 private :
69    int  parseXml ();
70    int  readLine ();
71    EnumItem  readItem  (std::string& item);
72    EnumItem  getItem   (std::string& item, EnumItem waited=M_NONE);
73    int       getString (std::string& item);
74    int       getIdent  (std::string& item);
75    int       getChar   ();
76    void      putError  (cpchar why);
77
78 private :
79    std::string   item_name;
80    std::string   item_vide;
81    int      nbr_attributs;
82    int      nbr_items;
83    XmlTree* xml_parent;
84
85    std::vector <std::string>   tab_attributs;
86    std::vector <std::string>   tab_values;
87    std::vector <XmlTree*> tab_items;
88                                // Lecture
89    std::string   fic_buffer;
90    int      len_buffer;
91    int      nro_ligne;
92    int      fic_pos;
93    int      pos_flow;
94    pfile    xml_file;
95    cpchar   xml_flow;
96    bool     xml_ended;
97 };
98 END_NAMESPACE_HEXA
99 #endif