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=========================================================================*/
29#ifndef vtkXMLDataParser_h
30#define vtkXMLDataParser_h
31
32#include "vtkIOXMLParserModule.h" // For export macro
33#include "vtkXMLDataElement.h" //For inline definition.
34#include "vtkXMLParser.h"
35
36class vtkInputStream;
38
39class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
40{
41public:
43 void PrintSelf(ostream& os, vtkIndent indent) override;
45
50
54 enum
55 {
57 LittleEndian
58 };
59
64 size_t ReadInlineData(vtkXMLDataElement* element, int isAscii, void* buffer,
65 vtkTypeUInt64 startWord, size_t numWords, int wordType);
67 vtkXMLDataElement* element, int isAscii, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
68 {
69 return this->ReadInlineData(element, isAscii, buffer, startWord, numWords, VTK_CHAR);
70 }
71
77 vtkTypeInt64 offset, void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
79 vtkTypeInt64 offset, char* buffer, vtkTypeUInt64 startWord, size_t numWords)
80 {
81 return this->ReadAppendedData(offset, buffer, startWord, numWords, VTK_CHAR);
82 }
83
88 size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord, size_t numWords, int wordType);
89
94 size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord, size_t maxWords, int wordType);
95
97
102 vtkGetObjectMacro(Compressor, vtkDataCompressor);
104
108 size_t GetWordTypeSize(int wordType);
109
114 int Parse() override;
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 void CharacterDataHandler(const char* data, int length) override;
154
159 vtkTypeInt64 GetAppendedDataPosition() { return this->AppendedDataPosition; }
160
161protected:
164
165 // This parser does not support parsing from a string.
166 int Parse(const char*) override;
167 int Parse(const char*, unsigned int) override;
168
169 // Implement parsing methods.
170 void StartElement(const char* name, const char** atts) override;
171 void EndElement(const char*) override;
172
173 int ParsingComplete() override;
176 int ParseBuffer(const char* buffer, unsigned int count) override;
177
182 void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
183
184 // Data reading methods.
186 size_t FindBlockSize(vtkTypeUInt64 block);
187 int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
188 unsigned char* ReadBlock(vtkTypeUInt64 block);
190 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
192 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
193
194 // Go to the start of the inline data
196
197 // Ascii data reading methods.
198 int ParseAsciiData(int wordType);
200
201 // Progress update methods.
203
204 // The root XML element.
206
207 // The stack of elements currently being parsed.
210 unsigned int OpenElementsSize;
211
212 // The position of the appended data section, if found.
214
215 // How much of the string "<AppendedData" has been matched in input.
217
218 // The byte order of the binary input.
220
221 // The word type of binary input headers.
223
224 // The input stream used to read data. Set by ReadAppendedData and
225 // ReadInlineData methods.
227
228 // The input stream used to read inline data. May transparently
229 // decode the data.
231
232 // The stream to use for appended data.
234
235 // Decompression data.
241 vtkTypeInt64* BlockStartOffsets;
242
243 // Ascii data parsing.
244 unsigned char* AsciiDataBuffer;
247 vtkTypeInt64 AsciiDataPosition;
248
249 // Progress during reading of data.
250 float Progress;
251
252 // Abort flag checked during reading of data.
253 int Abort;
254
256
257private:
258 vtkXMLDataParser(const vtkXMLDataParser&) = delete;
259 void operator=(const vtkXMLDataParser&) = delete;
260};
261
262//----------------------------------------------------------------------------
264{
265 const unsigned int eid = this->NumberOfOpenElements - 1;
267}
268
269#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)
@ length
Definition: vtkX3D.h:399
@ name
Definition: vtkX3D.h:225
@ offset
Definition: vtkX3D.h:444
@ progress
Definition: vtkX3D.h:458
@ data
Definition: vtkX3D.h:321
#define VTK_ENCODING_UNKNOWN
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:45