VTK  9.4.20241108
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
20#ifndef vtkXMLDataParser_h
21#define vtkXMLDataParser_h
22
23#include "vtkIOXMLParserModule.h" // For export macro
24#include "vtkXMLDataElement.h" //For inline definition.
25#include "vtkXMLParser.h"
26
27VTK_ABI_NAMESPACE_BEGIN
28class vtkInputStream;
30
31class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
32{
33public:
35 void PrintSelf(ostream& os, vtkIndent indent) override;
37
42
46 enum
47 {
49 LittleEndian
50 };
51
56 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii, void* buffer,
57 vtkTypeUInt64 startWord, size_t numWords, int wordType);
59 vtkXMLDataElement* element, int isAscii, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
60 {
61 return this->ReadInlineData(element, isAscii, buffer, startWord, numWords, VTK_CHAR);
62 }
63
69 vtkTypeInt64 offset, void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
71 vtkTypeInt64 offset, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
72 {
73 return this->ReadAppendedData(offset, buffer, startWord, numWords, VTK_CHAR);
74 }
75
80 size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
81
86 size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord, size_t maxWords, int wordType);
87
89
94 vtkGetObjectMacro(Compressor, vtkDataCompressor);
96
100 size_t GetWordTypeSize(int wordType);
101
106 int Parse() override;
107
109
113 vtkGetMacro(Abort, int);
114 vtkSetMacro(Abort, int);
116
118
122 vtkGetMacro(Progress, float);
123 vtkSetMacro(Progress, float);
125
127
135 vtkSetClampMacro(AttributesEncoding, int, VTK_ENCODING_NONE, VTK_ENCODING_UNKNOWN);
136 vtkGetMacro(AttributesEncoding, int);
138
145 void CharacterDataHandler(const char* data, int length) override;
146
151 vtkTypeInt64 GetAppendedDataPosition() { return this->AppendedDataPosition; }
152
153protected:
156
157 // This parser does not support parsing from a string.
158 int Parse(const char*) override;
159 int Parse(const char*, unsigned int) override;
160
161 // Implement parsing methods.
162 void StartElement(const char* name, const char** atts) override;
163 void EndElement(const char*) override;
164
165 int ParsingComplete() override;
168 int ParseBuffer(const char* buffer, unsigned int count) override;
169
174 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
175
176 // Data reading methods.
178 size_t FindBlockSize(vtkTypeUInt64 block);
179 int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
180 unsigned char* ReadBlock(vtkTypeUInt64 block);
182 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
184 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
185
186 // Go to the start of the inline data
188
189 // Ascii data reading methods.
190 int ParseAsciiData(int wordType);
192
193 // Progress update methods.
194 void UpdateProgress(float progress);
195
196 // The root XML element.
198
199 // The stack of elements currently being parsed.
202 unsigned int OpenElementsSize;
203
204 // The position of the appended data section, if found.
206
207 // How much of the string "<AppendedData" has been matched in input.
209
210 // Whether AppendedData has been dealt with or not.
212
213 // The byte order of the binary input.
215
216 // The word type of binary input headers.
218
219 // The input stream used to read data. Set by ReadAppendedData and
220 // ReadInlineData methods.
222
223 // The input stream used to read inline data. May transparently
224 // decode the data.
226
227 // The stream to use for appended data.
229
230 // Decompression data.
236 vtkTypeInt64* BlockStartOffsets;
237
238 // Ascii data parsing.
239 unsigned char* AsciiDataBuffer;
242 vtkTypeInt64 AsciiDataPosition;
243
244 // Progress during reading of data.
245 float Progress;
246
247 // Abort flag checked during reading of data.
248 int Abort;
249
251
252private:
253 vtkXMLDataParser(const vtkXMLDataParser&) = delete;
254 void operator=(const vtkXMLDataParser&) = delete;
255};
256
257//----------------------------------------------------------------------------
258inline void vtkXMLDataParser::CharacterDataHandler(const char* data, int length)
259{
260 const unsigned int eid = this->NumberOfOpenElements - 1;
261 this->OpenElements[eid]->AddCharacterData(data, length);
262}
263
264VTK_ABI_NAMESPACE_END
265#endif
Abstract interface for data compression classes.
a simple class to control print indentation
Definition vtkIndent.h:108
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