Salome HOME
Synchronize adm files
[modules/yacs.git] / src / yacsloader / parserBase.hxx
1 // Copyright (C) 2006-2014  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, 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 #ifndef _PARSERBASE_HXX_
21 #define _PARSERBASE_HXX_
22
23 #include "YACSloaderExport.hxx"
24
25 #include <expat.h>
26 #include <stack>
27 #include <map>
28 #include <string>
29 #include <iostream>
30
31 namespace YACS
32 {
33
34 struct YACSLOADER_EXPORT parser
35 {
36   static parser main_parser;
37
38   parser():_level(0),_defaultParsersMap(0)
39   {
40     _counts=new std::map<std::string,int>;
41   }
42   virtual ~parser();
43
44   virtual void SetUserDataAndPush(parser* pp);
45   virtual void onStart(const XML_Char *el, const XML_Char** attr);
46   static void XMLCALL start(void *data, const XML_Char* el, const XML_Char** attr);
47
48   virtual void onEnd(const XML_Char *el,parser* child);
49     
50   static void XMLCALL end(void *data, const char *el);
51     
52   virtual void charData(const XML_Char *s, int len);
53   
54   static void XMLCALL charac(void *data, const XML_Char *s, int len);
55     
56   virtual void endParser();
57     
58   virtual void init();
59     
60   virtual void incrCount(const XML_Char *el);
61     
62   virtual void checkOrder(std::string& el);
63     
64   virtual void maxcount(std::string name, int max, std::string& el);
65     
66   virtual void mincount(std::string name,int min );
67     
68   virtual void maxchoice(std::string *names, int max, std::string& el);
69     
70   virtual void minchoice(std::string *names, int min);
71     
72   virtual void pre(){_content="";};
73   virtual void required(const std::string& name, const XML_Char** attr);
74     
75   virtual void buildAttr(const XML_Char** attr);
76     
77   std::stack<parser*>& getStack();
78
79   template<class T>
80   T post() { }
81
82   void logError(const std::string& reason);
83
84   std::string _file;
85   std::string _content;
86   std::map<std::string,int> *_counts;
87   std::map<std::string,int> _orders;
88   int _orderState;
89   int _level;
90   std::stack<std::map<std::string,int>*> _stackCount;
91   std::stack<int> _stackOrder;
92   // OCC: san -- Allow external parsers for handling of unknown elements
93   // and attributes. This capability is used by YACS GUI to read
94   // graph presentation data
95   std::map<std::string,parser*> *_defaultParsersMap;
96 };
97
98 }
99 #endif