Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

IO/vtkXMLDataParser.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkXMLDataParser.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00042 #ifndef __vtkXMLDataParser_h
00043 #define __vtkXMLDataParser_h
00044 
00045 #include "vtkXMLParser.h"
00046 
00047 class vtkXMLDataElement;
00048 class vtkInputStream;
00049 class vtkDataCompressor;
00050 
00051 class VTK_IO_EXPORT vtkXMLDataParser : public vtkXMLParser
00052 {
00053 public:
00054   vtkTypeRevisionMacro(vtkXMLDataParser,vtkXMLParser);
00055   void PrintSelf(ostream& os, vtkIndent indent);
00056   static vtkXMLDataParser* New();
00057   
00058   //BTX
00060   /*! Enumerate big and little endian byte order settings. */
00061   enum { BigEndian, LittleEndian };
00062   //ETX
00064   
00066   vtkXMLDataElement* GetRootElement();
00067   
00069 
00071   unsigned long ReadInlineData(vtkXMLDataElement* element, int isAscii,
00072                                void* buffer, int startWord, int numWords,
00073                                int wordType);
00074   unsigned long ReadInlineData(vtkXMLDataElement* element, int isAscii,
00075                                char* buffer, int startWord, int numWords)
00076     { return this->ReadInlineData(element, isAscii, buffer, startWord,
00077                                   numWords, VTK_CHAR); }
00079   
00081 
00083   unsigned long ReadAppendedData(unsigned long offset, void* buffer,
00084                                  int startWord, int numWords, int wordType);
00085   unsigned long ReadAppendedData(unsigned long offset, char* buffer,
00086                                  int startWord, int numWords)
00087     { return this->ReadAppendedData(offset, buffer, startWord, numWords,
00088                                     VTK_CHAR); }
00090   
00092 
00094   unsigned long ReadAsciiData(void* buffer, int startWord, int numWords,
00095                               int wordType);
00097   
00099 
00101   unsigned long ReadBinaryData(void* buffer, int startWord, int maxWords,
00102                                int wordType);
00104   
00106 
00108   virtual void SetCompressor(vtkDataCompressor*);
00109   vtkGetObjectMacro(Compressor, vtkDataCompressor);
00111   
00113   unsigned long GetWordTypeSize(int wordType);
00114 
00117   virtual int Parse();
00118 
00119 protected:
00120   vtkXMLDataParser();
00121   ~vtkXMLDataParser();
00122   
00123   // This parser does not support parsing from a string.
00124   virtual int Parse(const char*);
00125   virtual int Parse(const char*, unsigned int);
00126   
00127   // Implement parsing methods.
00128   void StartElement(const char* name, const char** atts);
00129   void EndElement(const char*);
00130   int ParsingComplete();
00131   void ClearStreamEOF();
00132   int CheckPrimaryAttributes();
00133   void FindAppendedDataPosition();
00134   unsigned long FindInlineDataPosition(unsigned long start);
00135   int ParseBuffer(const char* buffer, unsigned int count);
00136   
00137   void AddElement(vtkXMLDataElement* element);
00138   void PushOpenElement(vtkXMLDataElement* element);
00139   vtkXMLDataElement* PopOpenElement();
00140   void PerformByteSwap(void* data, int numWords, int wordSize);
00141   
00142   // Data reading methods.
00143   void ReadCompressionHeader();
00144   unsigned int FindBlockSize(unsigned int block);
00145   int ReadBlock(unsigned int block, unsigned char* buffer);
00146   unsigned char* ReadBlock(unsigned int block);
00147   unsigned long ReadUncompressedData(unsigned char* data, unsigned long offset,
00148                                      unsigned long length);
00149   unsigned long ReadCompressedData(unsigned char* data, unsigned long offset,
00150                                    unsigned long length);
00151   
00152   // Ascii data reading methods.
00153   int ParseAsciiData(int wordType);
00154   void FreeAsciiBuffer();
00155     
00156   // The root XML element.
00157   vtkXMLDataElement* RootElement;
00158   
00159   // The stack of elements currently being parsed.
00160   vtkXMLDataElement** OpenElements;
00161   unsigned int NumberOfOpenElements;
00162   unsigned int OpenElementsSize;
00163   
00164   // The position of the appended data section, if found.
00165   unsigned long AppendedDataPosition;
00166   
00167   // How much of the string "<AppendedData" has been matched in input.
00168   int AppendedDataMatched;
00169   
00170   // The byte order of the binary input.
00171   int ByteOrder;
00172   
00173   // The input stream used to read data.  Set by ReadAppendedData and
00174   // ReadInlineData methods.
00175   vtkInputStream* DataStream;
00176   
00177   // The input stream used to read inline data.  May transparently
00178   // decode the data.
00179   vtkInputStream* InlineDataStream;
00180   
00181   // The stream to use for appended data.
00182   vtkInputStream* AppendedDataStream;
00183   
00184   // Decompression data.
00185   vtkDataCompressor* Compressor;
00186   unsigned int NumberOfBlocks;
00187   unsigned int BlockUncompressedSize;
00188   unsigned int PartialLastBlockUncompressedSize;
00189   unsigned int* BlockCompressedSizes;
00190   unsigned long* BlockStartOffsets;
00191   
00192   // Ascii data parsing.
00193   unsigned char* AsciiDataBuffer;
00194   int AsciiDataBufferLength;
00195   int AsciiDataWordType;
00196   unsigned long AsciiDataPosition;
00197   
00198 private:
00199   vtkXMLDataParser(const vtkXMLDataParser&);  // Not implemented.
00200   void operator=(const vtkXMLDataParser&);  // Not implemented.
00201 };
00202 
00203 #endif