Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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 =========================================================================*/
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   //BTX
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   //ETX
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   // This parser does not support parsing from a string.
00146   virtual int Parse(const char*);
00147   virtual int Parse(const char*, unsigned int);
00148 
00149   // Implement parsing methods.
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   // Data reading methods.
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   // Ascii data reading methods.
00179   int ParseAsciiData(int wordType);
00180   void FreeAsciiBuffer();
00181 
00182   // Progress update methods.
00183   void UpdateProgress(float progress);
00184 
00185   // The root XML element.
00186   vtkXMLDataElement* RootElement;
00187 
00188   // The stack of elements currently being parsed.
00189   vtkXMLDataElement** OpenElements;
00190   unsigned int NumberOfOpenElements;
00191   unsigned int OpenElementsSize;
00192 
00193   // The position of the appended data section, if found.
00194   OffsetType AppendedDataPosition;
00195 
00196   // How much of the string "<AppendedData" has been matched in input.
00197   int AppendedDataMatched;
00198 
00199   // The byte order of the binary input.
00200   int ByteOrder;
00201 
00202   // The input stream used to read data.  Set by ReadAppendedData and
00203   // ReadInlineData methods.
00204   vtkInputStream* DataStream;
00205 
00206   // The input stream used to read inline data.  May transparently
00207   // decode the data.
00208   vtkInputStream* InlineDataStream;
00209 
00210   // The stream to use for appended data.
00211   vtkInputStream* AppendedDataStream;
00212 
00213   //BTX
00214   // We need a 32 bit unsigned integer type for platform-independent
00215   // binary headers.  Note that this is duplicated in vtkXMLWriter.h.
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   //ETX
00226 
00227   // Decompression data.
00228   vtkDataCompressor* Compressor;
00229   unsigned int NumberOfBlocks;
00230   unsigned int BlockUncompressedSize;
00231   unsigned int PartialLastBlockUncompressedSize;
00232   HeaderType* BlockCompressedSizes;
00233   OffsetType* BlockStartOffsets;
00234 
00235   // Ascii data parsing.
00236   unsigned char* AsciiDataBuffer;
00237   OffsetType AsciiDataBufferLength;
00238   int AsciiDataWordType;
00239   OffsetType AsciiDataPosition;
00240 
00241   // Progress during reading of data.
00242   float Progress;
00243 
00244   // Abort flag checked during reading of data.
00245   int Abort;
00246 
00247   int AttributesEncoding;
00248 
00249 private:
00250   vtkXMLDataParser(const vtkXMLDataParser&);  // Not implemented.
00251   void operator=(const vtkXMLDataParser&);  // Not implemented.
00252 };
00253 
00254 #endif

Generated on Mon Jan 21 23:07:32 2008 for VTK by  doxygen 1.4.3-20050530