VTK
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 "vtkXMLParser.h"
34 #include "vtkXMLDataElement.h"//For inline definition.
35 
36 class vtkInputStream;
37 class vtkDataCompressor;
38 
39 class VTKIOXMLPARSER_EXPORT vtkXMLDataParser : public vtkXMLParser
40 {
41 public:
43  void PrintSelf(ostream& os, vtkIndent indent) override;
44  static vtkXMLDataParser* New();
45 
49  vtkXMLDataElement* GetRootElement();
50 
54  enum { BigEndian, LittleEndian };
55 
60  size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
61  void* buffer, vtkTypeUInt64 startWord,
62  size_t numWords, int wordType);
63  size_t ReadInlineData(vtkXMLDataElement* element, int isAscii,
64  char* buffer, vtkTypeUInt64 startWord,
65  size_t numWords)
66  { return this->ReadInlineData(element, isAscii, buffer, startWord,
67  numWords, VTK_CHAR); }
68 
73  size_t ReadAppendedData(vtkTypeInt64 offset, void* buffer,
74  vtkTypeUInt64 startWord,
75  size_t numWords, int wordType);
76  size_t ReadAppendedData(vtkTypeInt64 offset, char* buffer,
77  vtkTypeUInt64 startWord,
78  size_t numWords)
79  { return this->ReadAppendedData(offset, buffer, startWord, numWords,
80  VTK_CHAR); }
81 
86  size_t ReadAsciiData(void* buffer, vtkTypeUInt64 startWord,
87  size_t numWords, int wordType);
88 
93  size_t ReadBinaryData(void* buffer, vtkTypeUInt64 startWord,
94  size_t maxWords, int wordType);
95 
97 
101  virtual void SetCompressor(vtkDataCompressor*);
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()
160  {
161  return this->AppendedDataPosition;
162  }
163 
164 protected:
166  ~vtkXMLDataParser() override;
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;
177  int CheckPrimaryAttributes();
178  void FindAppendedDataPosition();
179  int ParseBuffer(const char* buffer, unsigned int count) override;
180 
181  void AddElement(vtkXMLDataElement* element);
182  void PushOpenElement(vtkXMLDataElement* element);
183  vtkXMLDataElement* PopOpenElement();
184  void FreeAllElements();
185  void PerformByteSwap(void* data, size_t numWords, size_t wordSize);
186 
187  // Data reading methods.
188  int ReadCompressionHeader();
189  size_t FindBlockSize(vtkTypeUInt64 block);
190  int ReadBlock(vtkTypeUInt64 block, unsigned char* buffer);
191  unsigned char* ReadBlock(vtkTypeUInt64 block);
192  size_t ReadUncompressedData(unsigned char* data,
193  vtkTypeUInt64 startWord,
194  size_t numWords,
195  size_t wordSize);
196  size_t ReadCompressedData(unsigned char* data,
197  vtkTypeUInt64 startWord,
198  size_t numWords,
199  size_t wordSize);
200 
201  // Go to the start of the inline data
202  void SeekInlineDataPosition(vtkXMLDataElement *element);
203 
204  // Ascii data reading methods.
205  int ParseAsciiData(int wordType);
206  void FreeAsciiBuffer();
207 
208  // Progress update methods.
209  void UpdateProgress(float progress);
210 
211  // The root XML element.
213 
214  // The stack of elements currently being parsed.
216  unsigned int NumberOfOpenElements;
217  unsigned int OpenElementsSize;
218 
219  // The position of the appended data section, if found.
220  vtkTypeInt64 AppendedDataPosition;
221 
222  // How much of the string "<AppendedData" has been matched in input.
224 
225  // The byte order of the binary input.
227 
228  // The word type of binary input headers.
230 
231  // The input stream used to read data. Set by ReadAppendedData and
232  // ReadInlineData methods.
234 
235  // The input stream used to read inline data. May transparently
236  // decode the data.
238 
239  // The stream to use for appended data.
241 
242  // Decompression data.
248  vtkTypeInt64* BlockStartOffsets;
249 
250  // Ascii data parsing.
251  unsigned char* AsciiDataBuffer;
254  vtkTypeInt64 AsciiDataPosition;
255 
256  // Progress during reading of data.
257  float Progress;
258 
259  // Abort flag checked during reading of data.
260  int Abort;
261 
263 
264 private:
265  vtkXMLDataParser(const vtkXMLDataParser&) = delete;
266  void operator=(const vtkXMLDataParser&) = delete;
267 };
268 
269 //----------------------------------------------------------------------------
270 inline
272 {
273  const unsigned int eid=this->NumberOfOpenElements-1;
274  this->OpenElements[eid]->AddCharacterData(data, length);
275 }
276 
277 
278 #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:42
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
virtual void CharacterDataHandler(const char *data, int length)
vtkTypeInt64 AsciiDataPosition
a simple class to control print indentation
Definition: vtkIndent.h:39
size_t ReadAppendedData(vtkTypeInt64 offset, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:49
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