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) VTK_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() VTK_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) VTK_OVERRIDE;
154 
159  vtkTypeInt64 GetAppendedDataPosition()
160  {
161  return this->AppendedDataPosition;
162  }
163 
164 protected:
166  ~vtkXMLDataParser() VTK_OVERRIDE;
167 
168  // This parser does not support parsing from a string.
169  int Parse(const char*) VTK_OVERRIDE;
170  int Parse(const char*, unsigned int) VTK_OVERRIDE;
171 
172  // Implement parsing methods.
173  void StartElement(const char* name, const char** atts) VTK_OVERRIDE;
174  void EndElement(const char*) VTK_OVERRIDE;
175 
176  int ParsingComplete() VTK_OVERRIDE;
177  int CheckPrimaryAttributes();
178  void FindAppendedDataPosition();
179  int ParseBuffer(const char* buffer, unsigned int count) VTK_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.
212  vtkXMLDataElement* RootElement;
213 
214  // The stack of elements currently being parsed.
215  vtkXMLDataElement** OpenElements;
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.
223  int AppendedDataMatched;
224 
225  // The byte order of the binary input.
226  int ByteOrder;
227 
228  // The word type of binary input headers.
229  int HeaderType;
230 
231  // The input stream used to read data. Set by ReadAppendedData and
232  // ReadInlineData methods.
233  vtkInputStream* DataStream;
234 
235  // The input stream used to read inline data. May transparently
236  // decode the data.
237  vtkInputStream* InlineDataStream;
238 
239  // The stream to use for appended data.
240  vtkInputStream* AppendedDataStream;
241 
242  // Decompression data.
243  vtkDataCompressor* Compressor;
244  size_t NumberOfBlocks;
245  size_t BlockUncompressedSize;
246  size_t PartialLastBlockUncompressedSize;
247  size_t* BlockCompressedSizes;
248  vtkTypeInt64* BlockStartOffsets;
249 
250  // Ascii data parsing.
251  unsigned char* AsciiDataBuffer;
252  size_t AsciiDataBufferLength;
253  int AsciiDataWordType;
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 
262  int AttributesEncoding;
263 
264 private:
265  vtkXMLDataParser(const vtkXMLDataParser&) VTK_DELETE_FUNCTION;
266  void operator=(const vtkXMLDataParser&) VTK_DELETE_FUNCTION;
267 };
268 
269 //----------------------------------------------------------------------------
270 inline
271 void vtkXMLDataParser::CharacterDataHandler(const char* data, int length )
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:39
Represents an XML element and those nested inside.
#define VTK_ENCODING_UNKNOWN
Wraps a binary input stream with a VTK interface.
void AddCharacterData(const char *c, size_t length)
Set/Get the character data between XML start/end tags.
a simple class to control print indentation
Definition: vtkIndent.h:33
size_t ReadAppendedData(vtkTypeInt64 offset, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
#define VTK_ENCODING_NONE
#define VTK_CHAR
Definition: vtkType.h:49
size_t ReadInlineData(vtkXMLDataElement *element, int isAscii, char *buffer, vtkTypeUInt64 startWord, size_t numWords)
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Used by vtkXMLReader to parse VTK XML files.
static vtkXMLParser * New()