VTK  9.1.0
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=========================================================================*/
32#ifndef vtkXMLDataParser_h
33#define vtkXMLDataParser_h
34
35#include "vtkIOXMLParserModule.h" // For export macro
36#include "vtkXMLDataElement.h" //For inline definition.
37#include "vtkXMLParser.h"
38
39class vtkInputStream;
41
42class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
43{
44public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
48
53
57 enum
58 {
60 LittleEndian
61 };
62
67 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii, void* buffer,
68 vtkTypeUInt64 startWord, size_t numWords, int wordType);
70 vtkXMLDataElement* element, int isAscii, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
71 {
72 return this->ReadInlineData(element, isAscii, buffer, startWord, numWords, VTK_CHAR);
73 }
74
80 vtkTypeInt64 offset, void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
82 vtkTypeInt64 offset, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
83 {
84 return this->ReadAppendedData(offset, buffer, startWord, numWords, VTK_CHAR);
85 }
86
91 size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
92
97 size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord, size_t maxWords, int wordType);
98
100
105 vtkGetObjectMacro(Compressor, vtkDataCompressor);
107
111 size_t GetWordTypeSize(int wordType);
112
117 int Parse() override;
118
120
124 vtkGetMacro(Abort, int);
125 vtkSetMacro(Abort, int);
127
129
133 vtkGetMacro(Progress, float);
134 vtkSetMacro(Progress, float);
136
138
146 vtkSetClampMacro(AttributesEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
147 vtkGetMacro(AttributesEncoding, int);
149
156 void CharacterDataHandler(const char* data, int length) override;
157
162 vtkTypeInt64 GetAppendedDataPosition() { return this->AppendedDataPosition; }
163
164protected:
167
168 // This parser does not support parsing from a string.
169 int Parse(const char*) override;
170 int Parse(const char*, unsigned int) override;
171
172 // Implement parsing methods.
173 void StartElement(const char* name, const char** atts) override;
174 void EndElement(const char*) override;
175
176 int ParsingComplete() override;
179 int ParseBuffer(const char* buffer, unsigned int count) override;
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);
193 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
195 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
196
197 // Go to the start of the inline data
199
200 // Ascii data reading methods.
201 int ParseAsciiData(int wordType);
203
204 // Progress update methods.
205 void UpdateProgress(float progress);
206
207 // The root XML element.
209
210 // The stack of elements currently being parsed.
213 unsigned int OpenElementsSize;
214
215 // The position of the appended data section, if found.
217
218 // How much of the string "<AppendedData" has been matched in input.
220
221 // The byte order of the binary input.
223
224 // The word type of binary input headers.
226
227 // The input stream used to read data. Set by ReadAppendedData and
228 // ReadInlineData methods.
230
231 // The input stream used to read inline data. May transparently
232 // decode the data.
234
235 // The stream to use for appended data.
237
238 // Decompression data.
244 vtkTypeInt64* BlockStartOffsets;
245
246 // Ascii data parsing.
247 unsigned char* AsciiDataBuffer;
250 vtkTypeInt64 AsciiDataPosition;
251
252 // Progress during reading of data.
253 float Progress;
254
255 // Abort flag checked during reading of data.
256 int Abort;
257
259
260private:
261 vtkXMLDataParser(const vtkXMLDataParser&) = delete;
262 void operator=(const vtkXMLDataParser&) = delete;
263};
264
265//----------------------------------------------------------------------------
266inline void vtkXMLDataParser::CharacterDataHandler(const char* data, int length)
267{
268 const unsigned int eid = this->NumberOfOpenElements - 1;
269 this->OpenElements[eid]->AddCharacterData(data, length);
270}
271
272#endif
Abstract interface for data compression classes.
a simple class to control print indentation
Definition: vtkIndent.h:113
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)
Set/Get the character data between XML start/end tags.
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.
void UpdateProgress(float progress)
~vtkXMLDataParser() override
vtkXMLDataElement * PopOpenElement()
void FindAppendedDataPosition()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkXMLDataElement * RootElement
vtkXMLDataElement ** OpenElements
size_t PartialLastBlockUncompressedSize
size_t ReadUncompressedData(unsigned char *data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize)
void StartElement(const char *name, const char **atts) override
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.
int Parse() override
Parse the XML input and check that the file is safe to read.
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.
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
int Parse(const char *) override
Parse the XML message.
void FreeAsciiBuffer()
size_t GetWordTypeSize(int wordType)
Get the size of a word of the given type.
void CharacterDataHandler(const char *data, int length) override
If you need the text inside XMLElements, turn IgnoreCharacterData off.
vtkTypeInt64 AppendedDataPosition
void EndElement(const char *) override
int ParseBuffer(const char *buffer, unsigned int count) override
int ParseAsciiData(int wordType)
int Parse(const char *, unsigned int) override
Parse the XML message.
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)
int ParsingComplete() override
unsigned int OpenElementsSize
vtkTypeInt64 * BlockStartOffsets
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:40
virtual void CharacterDataHandler(const char *data, int length)
#define VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:45