VTK  9.3.1
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 
27 VTK_ABI_NAMESPACE_BEGIN
28 class vtkInputStream;
29 class vtkDataCompressor;
30 
31 class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
32 {
33 public:
35  void PrintSelf(ostream& os, vtkIndent indent) override;
36  static vtkXMLDataParser* New();
37 
41  vtkXMLDataElement* GetRootElement();
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 
68  size_t ReadAppendedData(
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 
93  virtual void SetCompressor(vtkDataCompressor*);
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 
153 protected:
155  ~vtkXMLDataParser() override;
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;
166  int CheckPrimaryAttributes();
167  void FindAppendedDataPosition();
168  int ParseBuffer(const char* buffer, unsigned int count) override;
169 
170  void AddElement(vtkXMLDataElement* element);
171  void PushOpenElement(vtkXMLDataElement* element);
172  vtkXMLDataElement* PopOpenElement();
173  void FreeAllElements();
174  void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
175 
176  // Data reading methods.
177  int ReadCompressionHeader();
178  size_t FindBlockSize(vtkTypeUInt64 block);
179  int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
180  unsigned char* ReadBlock(vtkTypeUInt64 block);
181  size_t ReadUncompressedData(
182  unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
183  size_t ReadCompressedData(
184  unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize);
185 
186  // Go to the start of the inline data
187  void SeekInlineDataPosition(vtkXMLDataElement* element);
188 
189  // Ascii data reading methods.
190  int ParseAsciiData(int wordType);
191  void FreeAsciiBuffer();
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.
201  unsigned int NumberOfOpenElements;
202  unsigned int OpenElementsSize;
203 
204  // The position of the appended data section, if found.
205  vtkTypeInt64 AppendedDataPosition;
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 
252 private:
253  vtkXMLDataParser(const vtkXMLDataParser&) = delete;
254  void operator=(const vtkXMLDataParser&) = delete;
255 };
256 
257 //----------------------------------------------------------------------------
259 {
260  const unsigned int eid = this->NumberOfOpenElements - 1;
261  this->OpenElements[eid]->AddCharacterData(data, length);
262 }
263 
264 VTK_ABI_NAMESPACE_END
265 #endif
virtual int Parse()
Parse the XML input.
Abstract interface for data compression classes.
Parse XML to handle element tags and attributes.
Definition: vtkXMLParser.h:28
Represents an XML element and those nested inside.
vtkInputStream * InlineDataStream
virtual void StartElement(const char *name, const char **atts)
vtkInputStream * AppendedDataStream
vtkTypeInt64 AppendedDataPosition
#define VTK_ENCODING_UNKNOWN
size_t * BlockCompressedSizes
Wraps a binary input stream with a VTK interface.
vtkXMLDataElement ** OpenElements
void AddCharacterData(const char *c, size_t length)
Set/Get the character data between XML start/end tags.
virtual void CharacterDataHandler(const char *data, int length)
vtkTypeInt64 AsciiDataPosition
a simple class to control print indentation
Definition: vtkIndent.h:28
size_t ReadAppendedData(vtkTypeInt64 offset, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:33
vtkXMLDataElement * RootElement
vtkDataCompressor * Compressor
vtkTypeInt64 GetAppendedDataPosition()
Returns the byte index of where appended data starts (if the file is using appended data)...
unsigned int NumberOfOpenElements
virtual int ParsingComplete()
vtkInputStream * DataStream
size_t ReadInlineData(vtkXMLDataElement *element, int isAscii, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void CharacterDataHandler(const char *data, int length) override
If you need the text inside XMLElements, turn IgnoreCharacterData off.
vtkTypeInt64 * BlockStartOffsets
Used by vtkXMLReader to parse VTK XML files.
virtual void EndElement(const char *name)
size_t PartialLastBlockUncompressedSize
virtual int ParseBuffer(const char *buffer, unsigned int count)
unsigned int OpenElementsSize
static vtkXMLParser * New()
unsigned char * AsciiDataBuffer