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
00141 protected:
00142 vtkXMLDataParser();
00143 ~vtkXMLDataParser();
00144
00145
00146 virtual int Parse(const char*);
00147 virtual int Parse(const char*, unsigned int);
00148
00149
00150 void StartElement(const char* name, const char** atts);
00151 void EndElement(const char*);
00152 int ParsingComplete();
00153 int CheckPrimaryAttributes();
00154 void FindAppendedDataPosition();
00155 OffsetType FindInlineDataPosition(OffsetType start);
00156 int ParseBuffer(const char* buffer, unsigned int count);
00157
00158 void AddElement(vtkXMLDataElement* element);
00159 void PushOpenElement(vtkXMLDataElement* element);
00160 vtkXMLDataElement* PopOpenElement();
00161 void FreeAllElements();
00162 void PerformByteSwap(void* data, OffsetType numWords, int wordSize);
00163
00164
00165 void ReadCompressionHeader();
00166 unsigned int FindBlockSize(unsigned int block);
00167 int ReadBlock(unsigned int block, unsigned char* buffer);
00168 unsigned char* ReadBlock(unsigned int block);
00169 OffsetType ReadUncompressedData(unsigned char* data,
00170 OffsetType startWord,
00171 OffsetType numWords,
00172 int wordSize);
00173 OffsetType ReadCompressedData(unsigned char* data,
00174 OffsetType startWord,
00175 OffsetType numWords,
00176 int wordSize);
00177
00178
00179 int ParseAsciiData(int wordType);
00180 void FreeAsciiBuffer();
00181
00182
00183 void UpdateProgress(float progress);
00184
00185
00186 vtkXMLDataElement* RootElement;
00187
00188
00189 vtkXMLDataElement** OpenElements;
00190 unsigned int NumberOfOpenElements;
00191 unsigned int OpenElementsSize;
00192
00193
00194 OffsetType AppendedDataPosition;
00195
00196
00197 int AppendedDataMatched;
00198
00199
00200 int ByteOrder;
00201
00202
00203
00204 vtkInputStream* DataStream;
00205
00206
00207
00208 vtkInputStream* InlineDataStream;
00209
00210
00211 vtkInputStream* AppendedDataStream;
00212
00213
00214
00215
00216 #if VTK_SIZEOF_SHORT == 4
00217 typedef unsigned short HeaderType;
00218 #elif VTK_SIZEOF_INT == 4
00219 typedef unsigned int HeaderType;
00220 #elif VTK_SIZEOF_LONG == 4
00221 typedef unsigned long HeaderType;
00222 #else
00223 # error "No native data type can represent an unsigned 32-bit integer."
00224 #endif
00225
00226
00227
00228 vtkDataCompressor* Compressor;
00229 unsigned int NumberOfBlocks;
00230 unsigned int BlockUncompressedSize;
00231 unsigned int PartialLastBlockUncompressedSize;
00232 HeaderType* BlockCompressedSizes;
00233 OffsetType* BlockStartOffsets;
00234
00235
00236 unsigned char* AsciiDataBuffer;
00237 OffsetType AsciiDataBufferLength;
00238 int AsciiDataWordType;
00239 OffsetType AsciiDataPosition;
00240
00241
00242 float Progress;
00243
00244
00245 int Abort;
00246
00247 int AttributesEncoding;
00248
00249 private:
00250 vtkXMLDataParser(const vtkXMLDataParser&);
00251 void operator=(const vtkXMLDataParser&);
00252 };
00253
00254 #endif