packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmXMLParser.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmXMLParser_h
13 #define cmXMLParser_h
14
15 #include "cmStandardIncludes.h"
16
17 extern "C"
18 {
19   void cmXMLParserStartElement(void*, const char*, const char**);
20   void cmXMLParserEndElement(void*, const char*);
21   void cmXMLParserCharacterDataHandler(void*, const char*, int);
22 }
23
24 /** \class cmXMLParser
25  * \brief Helper class for performing XML parsing
26  *
27  * Superclass for all XML parsers.
28  */
29 class cmXMLParser
30 {
31 public:
32   cmXMLParser();
33   virtual ~cmXMLParser();
34
35   //! Parse given XML string
36   virtual int Parse(const char* string);
37
38   //! Parse given XML file
39   virtual int ParseFile(const char* file);
40
41   /**
42    * When parsing fragments of XML or streaming XML, use the following
43    * three methods.  InitializeParser method initialize parser but does
44    * not perform any actual parsing.  ParseChunk parses framgent of
45    * XML. This has to match to what was already parsed. CleanupParser
46    * finishes parsing. If there were errors, CleanupParser will report
47    * them.
48    */
49   virtual int InitializeParser();
50   virtual int ParseChunk(const char* inputString,
51                          std::string::size_type length);
52   virtual int CleanupParser();
53
54 protected:
55   //! This variable is true if there was a parse error while parsing in
56   //chunks.
57   int ParseError;
58
59   //1 Expat parser structure.  Exists only during call to Parse().
60   void* Parser;
61
62   /**
63    * Called before each block of input is read from the stream to check if
64    * parsing is complete.  Can be replaced by subclasses to change the
65    * terminating condition for parsing.  Parsing always stops when the end of
66    * file is reached in the stream.
67    */
68
69   virtual int ParsingComplete();
70
71   /**
72    * Called when a new element is opened in the XML source.  Should be
73    * replaced by subclasses to handle each element.  name = Name of new
74    * element.  atts = Null-terminated array of attribute name/value pairs.
75    * Even indices are attribute names, and odd indices are values.
76    */
77   virtual void StartElement(const char* name, const char** atts);
78
79   //! Called at the end of an element in the XML source opened when
80   //StartElement was called.
81   virtual void EndElement(const char* name);
82
83   //! Called when there is character data to handle.
84   virtual void CharacterDataHandler(const char* data, int length);
85
86   //! Called by Parse to report an XML syntax error.
87   virtual void ReportXmlParseError();
88
89   /** Called by ReportXmlParseError with basic error info.  */
90   virtual void ReportError(int line, int column, const char* msg);
91
92   //! Utility for convenience of subclasses.  Wraps isspace C library
93   // routine.
94   static int IsSpace(char c);
95
96   //! Send the given buffer to the XML parser.
97   virtual int ParseBuffer(const char* buffer,
98                           std::string::size_type length);
99
100   //! Send the given c-style string to the XML parser.
101   int ParseBuffer(const char* buffer);
102
103   /** Helps subclasses search for attributes on elements.  */
104   static const char* FindAttribute(const char** atts, const char* attribute);
105
106   //! Callbacks for the expat
107   friend void cmXMLParserStartElement(void*, const char*, const char**);
108   friend void cmXMLParserEndElement(void*, const char*);
109   friend void cmXMLParserCharacterDataHandler(void*, const char*, int);
110 };
111
112 #endif