VTK
vtkXMLDataParser.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLDataParser.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
29#ifndef vtkXMLDataParser_h
30#define vtkXMLDataParser_h
31
32#include "vtkIOXMLParserModule.h" // For export macro
33#include "vtkXMLParser.h"
34#include "vtkXMLDataElement.h"//For inline definition.
35
36class vtkInputStream;
38
39class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
40{
41public:
43 void PrintSelf(ostream& os, vtkIndent indent);
45
50
54 enum { BigEndian, LittleEndian };
55
60 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
61 void* buffer, vtkTypeUInt64 startWord,
62 size_t numWords, int wordType);
63 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
64 char* buffer, vtkTypeUInt64 startWord,
65 size_t numWords)
66 { return this->ReadInlineData(element, isAscii, buffer, startWord,
67 numWords, VTK_CHAR); }
68
73 size_t ReadAppendedData(vtkTypeInt64 offset, void* buffer,
74 vtkTypeUInt64 startWord,
75 size_t numWords, int wordType);
76 size_t ReadAppendedData(vtkTypeInt64 offset, char* buffer,
77 vtkTypeUInt64 startWord,
78 size_t numWords)
79 { return this->ReadAppendedData(offset, buffer, startWord, numWords,
80 VTK_CHAR); }
81
86 size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord,
87 size_t numWords, int wordType);
88
93 size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord,
94 size_t maxWords, int wordType);
95
97
102 vtkGetObjectMacro(Compressor, vtkDataCompressor);
104
108 size_t GetWordTypeSize(int wordType);
109
114 virtual int Parse();
115
117
121 vtkGetMacro(Abort, int);
122 vtkSetMacro(Abort, int);
124
126
130 vtkGetMacro(Progress, float);
131 vtkSetMacro(Progress, float);
133
135
143 vtkSetClampMacro(AttributesEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
144 vtkGetMacro(AttributesEncoding, int);
146
153 virtual void CharacterDataHandler(const char* data, int length);
154
160 {
161 return this->AppendedDataPosition;
162 }
163
164protected:
167
168 // This parser does not support parsing from a string.
169 virtual int Parse(const char*);
170 virtual int Parse(const char*, unsigned int);
171
172 // Implement parsing methods.
173 virtual void StartElement(const char* name, const char** atts);
174 virtual void EndElement(const char*);
175
179 int ParseBuffer(const char* buffer, unsigned int count);
180
185 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
186
187 // Data reading methods.
189 size_t FindBlockSize(vtkTypeUInt64 block);
190 int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
191 unsigned char* ReadBlock(vtkTypeUInt64 block);
192 size_t ReadUncompressedData(unsigned char* data,
193 vtkTypeUInt64 startWord,
194 size_t numWords,
195 size_t wordSize);
196 size_t ReadCompressedData(unsigned char* data,
197 vtkTypeUInt64 startWord,
198 size_t numWords,
199 size_t wordSize);
200
201 // Go to the start of the inline data
203
204 // Ascii data reading methods.
205 int ParseAsciiData(int wordType);
207
208 // Progress update methods.
210
211 // The root XML element.
213
214 // The stack of elements currently being parsed.
217 unsigned int OpenElementsSize;
218
219 // The position of the appended data section, if found.
221
222 // How much of the string "<AppendedData" has been matched in input.
224
225 // The byte order of the binary input.
227
228 // The word type of binary input headers.
230
231 // The input stream used to read data. Set by ReadAppendedData and
232 // ReadInlineData methods.
234
235 // The input stream used to read inline data. May transparently
236 // decode the data.
238
239 // The stream to use for appended data.
241
242 // Decompression data.
248 vtkTypeInt64* BlockStartOffsets;
249
250 // Ascii data parsing.
251 unsigned char* AsciiDataBuffer;
254 vtkTypeInt64 AsciiDataPosition;
255
256 // Progress during reading of data.
257 float Progress;
258
259 // Abort flag checked during reading of data.
260 int Abort;
261
263
264private:
265 vtkXMLDataParser(const vtkXMLDataParser&) VTK_DELETE_FUNCTION;
266 void operator=(const vtkXMLDataParser&) VTK_DELETE_FUNCTION;
267};
268
269//----------------------------------------------------------------------------
270inline
272{
273 const unsigned int eid=this->NumberOfOpenElements-1;
275}
276
277
278#endif
Abstract interface for data compression classes.
a simple class to control print indentation
Definition: vtkIndent.h:40
Wraps a binary input stream with a VTK interface.
Represents an XML element and those nested inside.
void AddCharacterData(const char *c, size_t length)
Used by vtkXMLReader to parse VTK XML files.
static vtkXMLDataParser * New()
void PushOpenElement(vtkXMLDataElement *element)
int CheckPrimaryAttributes()
int ReadCompressionHeader()
virtual void SetCompressor(vtkDataCompressor *)
Get/Set the compressor used to decompress binary and appended data after reading from the file.
int ParseBuffer(const char *buffer, unsigned int count)
void UpdateProgress(float progress)
vtkXMLDataElement * PopOpenElement()
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void FindAppendedDataPosition()
vtkXMLDataElement * RootElement
vtkXMLDataElement ** OpenElements
size_t PartialLastBlockUncompressedSize
virtual void StartElement(const char *name, const char **atts)
size_t ReadUncompressedData(unsigned char *data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize)
size_t ReadAppendedData(vtkTypeInt64 offset, void *buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType)
Read from an appended data section starting at the given appended data offset.
virtual void CharacterDataHandler(const char *data, int length)
If you need the text inside XMLElements, turn IgnoreCharacterData off.
vtkInputStream * DataStream
vtkInputStream * InlineDataStream
int ReadBlock(vtkTypeUInt64 block, unsigned char *buffer)
size_t FindBlockSize(vtkTypeUInt64 block)
size_t ReadInlineData(vtkXMLDataElement *element, int isAscii, void *buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType)
Read inline data from inside the given element.
vtkInputStream * AppendedDataStream
void FreeAllElements()
vtkDataCompressor * Compressor
vtkTypeInt64 GetAppendedDataPosition()
Returns the byte index of where appended data starts (if the file is using appended data).
size_t ReadAsciiData(void *buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType)
Read from an ascii data section starting at the current position in the stream.
virtual void EndElement(const char *)
void SeekInlineDataPosition(vtkXMLDataElement *element)
size_t ReadAppendedData(vtkTypeInt64 offset, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
size_t ReadBinaryData(void *buffer, vtkTypeUInt64 startWord, size_t maxWords, int wordType)
Read from a data section starting at the current position in the stream.
size_t * BlockCompressedSizes
vtkXMLDataElement * GetRootElement()
Get the root element from the XML document.
vtkTypeInt64 AsciiDataPosition
unsigned int NumberOfOpenElements
void FreeAsciiBuffer()
virtual int Parse(const char *)
Parse the XML message.
size_t GetWordTypeSize(int wordType)
Get the size of a word of the given type.
vtkTypeInt64 AppendedDataPosition
virtual int Parse(const char *, unsigned int)
int ParseAsciiData(int wordType)
virtual int Parse()
Parse the XML input and check that the file is safe to read.
void AddElement(vtkXMLDataElement *element)
unsigned char * AsciiDataBuffer
size_t ReadCompressedData(unsigned char *data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize)
unsigned char * ReadBlock(vtkTypeUInt64 block)
void PerformByteSwap(void *data, size_t numWords, size_t wordSize)
size_t ReadInlineData(vtkXMLDataElement *element, int isAscii, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
unsigned int OpenElementsSize
vtkTypeInt64 * BlockStartOffsets
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:43
virtual void CharacterDataHandler(const char *data, int length)
@ length
Definition: vtkX3D.h:393
@ name
Definition: vtkX3D.h:219
@ offset
Definition: vtkX3D.h:438
@ progress
Definition: vtkX3D.h:452
@ data
Definition: vtkX3D.h:315
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
#define VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:49