1 // Copyright (C) 2006-2015 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, or (at your option) any later version.
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 #ifndef _PARSERBASE_HXX_
21 #define _PARSERBASE_HXX_
23 #include "YACSloaderExport.hxx"
30 #include <libxml/parser.h>
31 #include <libxml/tree.h>
32 #include <libxml/xmlreader.h>
37 typedef char XML_Char;
39 struct YACSLOADER_EXPORT parser
41 static parser main_parser;
42 static std::stack<parser*> _stackParser;
44 parser():_level(0),_defaultParsersMap(0)
46 _counts=new std::map<std::string,int>;
49 virtual void SetUserDataAndPush(parser* pp);
50 virtual void onStart(const XML_Char *el, const XML_Char** attr);
51 virtual void onEnd(const XML_Char *el, parser* child);
52 virtual void charData(const XML_Char *s, int len);
53 virtual void endParser();
55 virtual void incrCount(const XML_Char *elem);
56 virtual void checkOrder(std::string& el);
57 virtual void maxcount(std::string name, int max, std::string& el);
58 virtual void mincount(std::string name,int min );
59 virtual void maxchoice(std::string *names, int max, std::string& el);
60 virtual void minchoice(std::string *names, int min);
61 virtual void pre(){_content="";};
62 virtual void required(const std::string& name, const XML_Char** attr);
63 virtual void buildAttr(const XML_Char** attr);
65 static void XMLCALL start_document(void* data);
66 static void XMLCALL end_document (void* data);
67 static void XMLCALL start_element (void* data,
70 static void XMLCALL end_element (void* data,
72 static void XMLCALL characters (void* data,
75 static void XMLCALL comment (void* data,
76 const xmlChar* value);
77 static void XMLCALL cdata_block (void* data,
80 static void XMLCALL warning (void* data,
81 const char* fmt, ...);
82 static void XMLCALL error (void* data,
83 const char* fmt, ...);
84 static void XMLCALL fatal_error (void* data,
85 const char* fmt, ...);
87 static void XML_SetUserData(_xmlParserCtxt* ctxt, parser* par);
89 std::stack<parser*>& getStack();
94 void logError(const std::string& reason);
98 std::map<std::string,int> *_counts;
99 std::map<std::string,int> _orders;
102 std::stack<std::map<std::string,int>*> _stackCount;
103 std::stack<int> _stackOrder;
104 // OCC: san -- Allow external parsers for handling of unknown elements
105 // and attributes. This capability is used by YACS GUI to read
106 // graph presentation data
107 std::map<std::string,parser*> *_defaultParsersMap;