VTK  9.3.0
vtkXMLDataParser.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
17#ifndef vtkXMLDataParser_h
18#define vtkXMLDataParser_h
19
20#include "vtkIOXMLParserModule.h" // For export macro
21#include "vtkXMLDataElement.h" //For inline definition.
22#include "vtkXMLParser.h"
23
24VTK_ABI_NAMESPACE_BEGIN
25class vtkInputStream;
27
28class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
29{
30public:
32 void PrintSelf(ostream& os, vtkIndent indent) override;
34
39
43 enum
44 {
46 LittleEndian
47 };
48
53 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii, void* buffer,
54 vtkTypeUInt64 startWord, size_t numWords, int wordType);
56 vtkXMLDataElement* element, int isAscii, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
57 {
58 return this->ReadInlineData(element, isAscii, buffer, startWord, numWords, VTK_CHAR);
59 }
60
66 vtkTypeInt64 offset, void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
68 vtkTypeInt64 offset, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
69 {
70 return this->ReadAppendedData(offset, buffer, startWord, numWords, VTK_CHAR);
71 }
72
77 size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
78
83 size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord, size_t maxWords, int wordType);
84
86
91 vtkGetObjectMacro(Compressor, vtkDataCompressor);
93
97 size_t GetWordTypeSize(int wordType);
98
103 int Parse() override;
104
106
110 vtkGetMacro(Abort, int);
111 vtkSetMacro(Abort, int);
113
115
119 vtkGetMacro(Progress, float);
120 vtkSetMacro(Progress, float);
122
124
132 vtkSetClampMacro(AttributesEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
133 vtkGetMacro(AttributesEncoding, int);
135
142 void CharacterDataHandler(const char* data, int length) override;
143
148 vtkTypeInt64 GetAppendedDataPosition() { return this->AppendedDataPosition; }
149
150protected:
153
154 // This parser does not support parsing from a string.
155 int Parse(const char*) override;
156 int Parse(const char*, unsigned int) override;
157
158 // Implement parsing methods.
159 void StartElement(const char* name, const char** atts) override;
160 void EndElement(const char*) override;
161
162 int ParsingComplete() override;
165 int ParseBuffer(const char* buffer, unsigned int count) override;
166
171 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
172
173 // Data reading methods.
175 size_t FindBlockSize(vtkTypeUInt64 block);
176 int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
177 unsigned char* ReadBlock(vtkTypeUInt64 block);
179 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
181 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
182
183 // Go to the start of the inline data
185
186 // Ascii data reading methods.
187 int ParseAsciiData(int wordType);
189
190 // Progress update methods.
191 void UpdateProgress(float progress);
192
193 // The root XML element.
195
196 // The stack of elements currently being parsed.
199 unsigned int OpenElementsSize;
200
201 // The position of the appended data section, if found.
203
204 // How much of the string "<AppendedData" has been matched in input.
206
207 // Whether AppendedData has been dealt with or not.
209
210 // The byte order of the binary input.
212
213 // The word type of binary input headers.
215
216 // The input stream used to read data. Set by ReadAppendedData and
217 // ReadInlineData methods.
219
220 // The input stream used to read inline data. May transparently
221 // decode the data.
223
224 // The stream to use for appended data.
226
227 // Decompression data.
233 vtkTypeInt64* BlockStartOffsets;
234
235 // Ascii data parsing.
236 unsigned char* AsciiDataBuffer;
239 vtkTypeInt64 AsciiDataPosition;
240
241 // Progress during reading of data.
242 float Progress;
243
244 // Abort flag checked during reading of data.
245 int Abort;
246
248
249private:
250 vtkXMLDataParser(const vtkXMLDataParser&) = delete;
251 void operator=(const vtkXMLDataParser&) = delete;
252};
253
254//----------------------------------------------------------------------------
255inline void vtkXMLDataParser::CharacterDataHandler(const char* data, int length)
256{
257 const unsigned int eid = this->NumberOfOpenElements - 1;
258 this->OpenElements[eid]->AddCharacterData(data, length);
259}
260
261VTK_ABI_NAMESPACE_END
262#endif
Abstract interface for data compression classes.
a simple class to control print indentation
Definition vtkIndent.h:29
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.
virtual void CharacterDataHandler(const char *data, int length)
#define VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition vtkType.h:33