]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCK/HexXmlTree.hxx
Salome HOME
Porting HEXABLOCK module on WIN32 platform.
[modules/hexablock.git] / src / HEXABLOCK / HexXmlTree.hxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
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.
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 "Hex_defines.hxx"
26 #include "hexa_base.hxx"
27
28 #include <vector>
29
30 BEGIN_NAMESPACE_HEXA
31
32    enum EnumItem { M_NONE,  M_BEGIN, M_END, M_BEGIN_CLOSE, M_CLOSE,
33                    M_IDENT, M_EQUALS, M_STRING,
34                    M_COMMENT, M_END_COMMENT, M_PROLOG, M_END_PROLOG,
35                    M_ERROR};
36 class HEXABLOCKENGINE_EXPORT XmlTree
37 {
38 public :
39    XmlTree (const string& name, XmlTree* dad=NULL);
40   ~XmlTree ();
41
42    int  parseFile   (const string& name);
43    int  parseStream (cpchar flux, int& posit);
44
45    cpchar getName  ()   { return item_name.c_str() ; }
46    int    getNbrAttributs  ()   { return nbr_attributs ; }
47    int    getNbrChildren   ()   { return nbr_items     ; }
48
49    int           findAttribute (const string& nom);
50    const string& findValue     (const string& nom);
51    int           findInteger   (const string& nom);
52
53    cpchar   getAttribute  (int nro)    { return tab_attributs [nro].c_str(); }
54    cpchar   getValue      (int nro)    { return tab_values    [nro].c_str(); }
55
56    XmlTree* findChild    (const string& nom);
57    XmlTree* getChild     (int nro)    { return tab_items [nro]; }
58    XmlTree* getParent    ()           { return xml_parent; }
59
60                   // ------------------------- Modifications
61
62    XmlTree* addChild    (const string& nom);
63    void     addAttribut (const string& nom, const string& valeur);
64    void     setName     (const string&  nom)   { item_name = nom; }
65    void     dump        (int niveau=0);
66
67    int      goTo        (cpchar  ouca);
68
69 private :
70    int  parseXml ();
71    int  readLine ();
72    EnumItem  readItem  (string& item);
73    EnumItem  getItem   (string& item, EnumItem waited=M_NONE);
74    int       getString (string& item);
75    int       getIdent  (string& item);
76    int       getChar   ();
77    void      putError  (cpchar why);
78
79 private :
80    string   item_name;
81    string   item_vide;
82    int      nbr_attributs;
83    int      nbr_items;
84    XmlTree* xml_parent;
85
86    vector <string>   tab_attributs;
87    vector <string>   tab_values;
88    vector <XmlTree*> tab_items;
89                                // Lecture
90    string   fic_buffer;
91    int      len_buffer;
92    int      nro_ligne;
93    int      fic_pos;
94    int      pos_flow;
95    pfile    xml_file;
96    cpchar   xml_flow;
97    bool     xml_ended;
98 };
99 END_NAMESPACE_HEXA
100 #endif