Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkXMLDataParser.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkXMLDataParser.h,v $
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
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   //BTX
00059 
00060   enum { BigEndian, LittleEndian };
00061   //ETX
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   // This parser does not support parsing from a string.
00149   virtual int Parse(const char*);
00150   virtual int Parse(const char*, unsigned int);
00151 
00152   // Implement parsing methods.
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   // Data reading methods.
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   // Ascii data reading methods.
00182   int ParseAsciiData(int wordType);
00183   void FreeAsciiBuffer();
00184 
00185   // Progress update methods.
00186   void UpdateProgress(float progress);
00187 
00188   // The root XML element.
00189   vtkXMLDataElement* RootElement;
00190 
00191   // The stack of elements currently being parsed.
00192   vtkXMLDataElement** OpenElements;
00193   unsigned int NumberOfOpenElements;
00194   unsigned int OpenElementsSize;
00195 
00196   // The position of the appended data section, if found.
00197   unsigned long AppendedDataPosition;
00198 
00199   // How much of the string "<AppendedData" has been matched in input.
00200   int AppendedDataMatched;
00201 
00202   // The byte order of the binary input.
00203   int ByteOrder;
00204 
00205   // The input stream used to read data.  Set by ReadAppendedData and
00206   // ReadInlineData methods.
00207   vtkInputStream* DataStream;
00208 
00209   // The input stream used to read inline data.  May transparently
00210   // decode the data.
00211   vtkInputStream* InlineDataStream;
00212 
00213   // The stream to use for appended data.
00214   vtkInputStream* AppendedDataStream;
00215 
00216   //BTX
00217   // We need a 32 bit unsigned integer type for platform-independent
00218   // binary headers.  Note that this is duplicated in vtkXMLWriter.h.
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   //ETX
00229 
00230   // Decompression data.
00231   vtkDataCompressor* Compressor;
00232   unsigned int NumberOfBlocks;
00233   unsigned int BlockUncompressedSize;
00234   unsigned int PartialLastBlockUncompressedSize;
00235   HeaderType* BlockCompressedSizes;
00236   unsigned long* BlockStartOffsets;
00237 
00238   // Ascii data parsing.
00239   unsigned char* AsciiDataBuffer;
00240   int AsciiDataBufferLength;
00241   int AsciiDataWordType;
00242   unsigned long AsciiDataPosition;
00243 
00244   // Progress during reading of data.
00245   float Progress;
00246 
00247   // Abort flag checked during reading of data.
00248   int Abort;
00249 
00250   int AttributesEncoding;
00251 
00252 private:
00253   vtkXMLDataParser(const vtkXMLDataParser&);  // Not implemented.
00254   void operator=(const vtkXMLDataParser&);  // Not implemented.
00255 };
00256 
00257 #endif