File: vtkXMLParser.h

package info (click to toggle)
vtk 5.0.4-1.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 51,084 kB
  • ctags: 70,426
  • sloc: cpp: 524,166; ansic: 220,276; tcl: 43,377; python: 14,037; perl: 3,102; java: 1,436; yacc: 1,033; sh: 339; lex: 248; makefile: 197; asm: 154
file content (170 lines) | stat: -rw-r--r-- 5,857 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkXMLParser.h,v $

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// .NAME vtkXMLParser - Parse XML to handle element tags and attributes.
// .SECTION Description
// vtkXMLParser reads a stream and parses XML element tags and corresponding
// attributes.  Each element begin tag and its attributes are sent to
// the StartElement method.  Each element end tag is sent to the
// EndElement method.  Subclasses should replace these methods to actually
// use the tags.
// .SECTION ToDo: Add commands for parsing in Tcl.

#ifndef __vtkXMLParser_h
#define __vtkXMLParser_h

#include "vtkObject.h"

extern "C"
{
  void vtkXMLParserStartElement(void*, const char*, const char**);
  void vtkXMLParserEndElement(void*, const char*);
  void vtkXMLParserCharacterDataHandler(void*, const char*, int);
}

class VTK_IO_EXPORT vtkXMLParser : public vtkObject
{
public:
  vtkTypeRevisionMacro(vtkXMLParser,vtkObject);
  void PrintSelf(ostream& os, vtkIndent indent);

  static vtkXMLParser* New();

  //BTX
  // Description:
  // Get/Set the input stream.
  vtkSetMacro(Stream, istream*);
  vtkGetMacro(Stream, istream*);
  //ETX

  // Description:
  // Used by subclasses and their supporting classes.  These methods
  // wrap around the tellg and seekg methods of the input stream to
  // work-around stream bugs on various platforms.
  long TellG();
  void SeekG(long position);

  // Description:
  // Parse the XML input.
  virtual int Parse();

  // Description:
  // Parse the XML message. If length is specified, parse only the
  // first "length" characters
  virtual int Parse(const char* inputString);
  virtual int Parse(const char* inputString, unsigned int length);

  // Description:
  // When parsing fragments of XML or streaming XML, use the following
  // three methods.  InitializeParser method initialize parser but
  // does not perform any actual parsing.  ParseChunk parses framgent
  // of XML. This has to match to what was already
  // parsed. CleanupParser finishes parsing. If there were errors,
  // CleanupParser will report them.
  virtual int InitializeParser();
  virtual int ParseChunk(const char* inputString, unsigned int length);
  virtual int CleanupParser();

  // Description:
  // Set and get file name.
  vtkSetStringMacro(FileName);
  vtkGetStringMacro(FileName);

protected:
  vtkXMLParser();
  ~vtkXMLParser();

  // Input stream.  Set by user.
  istream* Stream;

  // File name to parse
  char* FileName;

  // This variable is true if there was a parse error while parsing in
  // chunks.
  int ParseError;

  // Character message to parse
  const char* InputString;
  int InputStringLength;

  // Expat parser structure.  Exists only during call to Parse().
  void* Parser;

  // Called by Parse() to read the stream and call ParseBuffer.  Can
  // be replaced by subclasses to change how input is read.
  virtual int ParseXML();

  // Called before each block of input is read from the stream to
  // check if parsing is complete.  Can be replaced by subclasses to
  // change the terminating condition for parsing.  Parsing always
  // stops when the end of file is reached in the stream.
  virtual int ParsingComplete();

  // Called when a new element is opened in the XML source.  Should be
  // replaced by subclasses to handle each element.
  //  name = Name of new element.
  //  atts = Null-terminated array of attribute name/value pairs.
  //         Even indices are attribute names, and odd indices are values.
  virtual void StartElement(const char* name, const char** atts);

  // Called at the end of an element in the XML source opened when
  // StartElement was called.
  virtual void EndElement(const char* name);

  // Called when there is character data to handle.
  virtual void CharacterDataHandler(const char* data, int length);

  // Called by begin handlers to report any stray attribute values.
  virtual void ReportStrayAttribute(const char* element, const char* attr,
                                    const char* value);

  // Called by begin handlers to report any missing attribute values.
  virtual void ReportMissingAttribute(const char* element, const char* attr);

  // Called by begin handlers to report bad attribute values.
  virtual void ReportBadAttribute(const char* element, const char* attr,
                                  const char* value);

  // Called by StartElement to report unknown element type.
  virtual void ReportUnknownElement(const char* element);

  // Called by Parse to report an XML syntax error.
  virtual void ReportXmlParseError();

  // Get the current byte index from the beginning of the XML stream.
  unsigned long GetXMLByteIndex();

  // Send the given buffer to the XML parser.
  virtual int ParseBuffer(const char* buffer, unsigned int count);

  // Send the given c-style string to the XML parser.
  int ParseBuffer(const char* buffer);

  // Utility for convenience of subclasses.  Wraps isspace C library
  // routine.
  static int IsSpace(char c);

  //BTX
  friend void vtkXMLParserStartElement(void*, const char*, const char**);
  friend void vtkXMLParserEndElement(void*, const char*);
  friend void vtkXMLParserCharacterDataHandler(void*, const char*, int);
  //ETX

private:
  vtkXMLParser(const vtkXMLParser&);  // Not implemented.
  void operator=(const vtkXMLParser&);  // Not implemented.
};

#endif