00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00031 #ifndef __vtkXMLDataParser_h
00032 #define __vtkXMLDataParser_h
00033
00034 #include "vtkXMLParser.h"
00035
00036 class vtkXMLDataElement;
00037 class vtkInputStream;
00038 class vtkDataCompressor;
00039
00040 class VTK_IO_EXPORT vtkXMLDataParser : public vtkXMLParser
00041 {
00042 public:
00043 vtkTypeRevisionMacro(vtkXMLDataParser,vtkXMLParser);
00044 void PrintSelf(ostream& os, vtkIndent indent);
00045 static vtkXMLDataParser* New();
00046
00048 vtkXMLDataElement* GetRootElement();
00049
00050
00052 enum { BigEndian, LittleEndian };
00053
00058 typedef vtkIdType OffsetType;
00059
00061
00063 OffsetType ReadInlineData(vtkXMLDataElement* element, int isAscii,
00064 void* buffer, OffsetType startWord,
00065 OffsetType numWords, int wordType);
00066 OffsetType ReadInlineData(vtkXMLDataElement* element, int isAscii,
00067 char* buffer, OffsetType startWord,
00068 OffsetType numWords)
00069 { return this->ReadInlineData(element, isAscii, buffer, startWord,
00070 numWords, VTK_CHAR); }
00072
00074
00076 OffsetType ReadAppendedData(OffsetType offset, void* buffer,
00077 OffsetType startWord,
00078 OffsetType numWords, int wordType);
00079 OffsetType ReadAppendedData(OffsetType offset, char* buffer,
00080 OffsetType startWord,
00081 OffsetType numWords)
00082 { return this->ReadAppendedData(offset, buffer, startWord, numWords,
00083 VTK_CHAR); }
00085
00087
00089 OffsetType ReadAsciiData(void* buffer, OffsetType startWord,
00090 OffsetType numWords, int wordType);
00092
00094
00096 OffsetType ReadBinaryData(void* buffer, OffsetType startWord,
00097 OffsetType maxWords, int wordType);
00098
00100
00102
00104 virtual void SetCompressor(vtkDataCompressor*);
00105 vtkGetObjectMacro(Compressor, vtkDataCompressor);
00107
00109 unsigned long GetWordTypeSize(int wordType);
00110
00113 virtual int Parse();
00114
00116
00118 vtkGetMacro(Abort, int);
00119 vtkSetMacro(Abort, int);
00121
00123
00125 vtkGetMacro(Progress, float);
00126 vtkSetMacro(Progress, float);
00128
00130
00137 vtkSetClampMacro(AttributesEncoding,int,VTK_ENCODING_NONE,VTK_ENCODING_UNKNOWN);
00138 vtkGetMacro(AttributesEncoding, int);
00140
00145 virtual void CharacterDataHandler(const char* data, int length);
00146
00147 protected:
00148 vtkXMLDataParser();
00149 ~vtkXMLDataParser();
00150
00151
00152 virtual int Parse(const char*);
00153 virtual int Parse(const char*, unsigned int);
00154
00155
00156 virtual void StartElement(const char* name, const char** atts);
00157 virtual void EndElement(const char*);
00158
00159 int ParsingComplete();
00160 int CheckPrimaryAttributes();
00161 void FindAppendedDataPosition();
00162 OffsetType FindInlineDataPosition(OffsetType start);
00163 int ParseBuffer(const char* buffer, unsigned int count);
00164
00165 void AddElement(vtkXMLDataElement* element);
00166 void PushOpenElement(vtkXMLDataElement* element);
00167 vtkXMLDataElement* PopOpenElement();
00168 void FreeAllElements();
00169 void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
00170
00171
00172 void ReadCompressionHeader();
00173 unsigned int FindBlockSize(unsigned int block);
00174 int ReadBlock(unsigned int block, unsigned char* buffer);
00175 unsigned char* ReadBlock(unsigned int block);
00176 OffsetType ReadUncompressedData(unsigned char* data,
00177 OffsetType startWord,
00178 OffsetType numWords,
00179 int wordSize);
00180 OffsetType ReadCompressedData(unsigned char* data,
00181 OffsetType startWord,
00182 OffsetType numWords,
00183 int wordSize);
00184
00185
00186 int ParseAsciiData(int wordType);
00187 void FreeAsciiBuffer();
00188
00189
00190 void UpdateProgress(float progress);
00191
00192
00193 vtkXMLDataElement* RootElement;
00194
00195
00196 vtkXMLDataElement** OpenElements;
00197 unsigned int NumberOfOpenElements;
00198 unsigned int OpenElementsSize;
00199
00200
00201 OffsetType AppendedDataPosition;
00202
00203
00204 int AppendedDataMatched;
00205
00206
00207 int ByteOrder;
00208
00209
00210
00211 vtkInputStream* DataStream;
00212
00213
00214
00215 vtkInputStream* InlineDataStream;
00216
00217
00218 vtkInputStream* AppendedDataStream;
00219
00220
00221
00222
00223 #if VTK_SIZEOF_SHORT == 4
00224 typedef unsigned short HeaderType;
00225 #elif VTK_SIZEOF_INT == 4
00226 typedef unsigned int HeaderType;
00227 #elif VTK_SIZEOF_LONG == 4
00228 typedef unsigned long HeaderType;
00229 #else
00230 # error "No native data type can represent an unsigned 32-bit integer."
00231 #endif
00232
00233
00234
00235 vtkDataCompressor* Compressor;
00236 unsigned int NumberOfBlocks;
00237 unsigned int BlockUncompressedSize;
00238 unsigned int PartialLastBlockUncompressedSize;
00239 HeaderType* BlockCompressedSizes;
00240 OffsetType* BlockStartOffsets;
00241
00242
00243 unsigned char* AsciiDataBuffer;
00244 OffsetType AsciiDataBufferLength;
00245 int AsciiDataWordType;
00246 OffsetType AsciiDataPosition;
00247
00248
00249 float Progress;
00250
00251
00252 int Abort;
00253
00254 int AttributesEncoding;
00255
00256 private:
00257 vtkXMLDataParser(const vtkXMLDataParser&);
00258 void operator=(const vtkXMLDataParser&);
00259 };
00260
00261 #endif