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