ZipCharStream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    ZipCharStream.h
00006  *
00007  *  ZipCharStream.h,v 1.6 2006/01/23 14:11:06 jwillemsen Exp
00008  *
00009  *  @author Krishnakumar B <kitty@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef _ACEXML_ZIPCHARSTREAM_H_
00014 #define _ACEXML_ZIPCHARSTREAM_H_
00015 
00016 #ifdef USE_ZZIP
00017 
00018 #include /**/ "ace/pre.h"
00019 #include "ACEXML/common/ACEXML_Export.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "ACEXML/common/CharStream.h"
00026 #include "ACEXML/common/Encoding.h"
00027 #include "zzip/zzip.h"
00028 
00029 // Ugly wart to get aroung a macro version of read defined in zzip.h. Evil...
00030 #ifdef read
00031 #undef read
00032 #endif
00033 
00034 /**
00035  * @class ACEXML_ZipCharStream
00036  *
00037  * An implementation of ACEXML_CharStream for reading input from a ZIP archive.
00038  */
00039 class ACEXML_Export ACEXML_ZipCharStream : public ACEXML_CharStream
00040 {
00041 public:
00042   /// Default constructor.
00043   ACEXML_ZipCharStream (void);
00044 
00045   /// Destructor
00046   virtual ~ACEXML_ZipCharStream (void);
00047 
00048   /// Open a file.
00049   int open (const ACEXML_Char *name);
00050 
00051   /**
00052    * Returns the available ACEXML_Char in the buffer.  -1
00053    * if the object is not initialized properly.
00054    */
00055   virtual int available (void);
00056 
00057   /**
00058    * Close this stream and release all resources used by it.
00059    */
00060   virtual int close (void);
00061 
00062   /**
00063    * Read the next ACEXML_Char.  Return -1 if we are not able to
00064    * return an ACEXML_Char, 0 if EOF is reached, or 1 if succeed.
00065    */
00066   virtual int get (ACEXML_Char& ch);
00067 
00068   /**
00069    * Read the next batch of ACEXML_Char strings
00070    */
00071   virtual int read (ACEXML_Char *str, size_t len);
00072 
00073   /**
00074    *  Determine the encoding of the file.
00075    */
00076   virtual int determine_encoding (void);
00077 
00078 
00079   /**
00080    * Peek the next ACEXML_Char in the CharStream.  Return the
00081    * character if success, -1 if EOF is reached.
00082    */
00083   virtual int peek (void);
00084 
00085   /**
00086    *  Resets the file pointer to the beginning of the stream.
00087    */
00088   virtual void rewind (void);
00089 
00090   /*
00091    * Get the character encoding for a byte stream or URI.
00092    */
00093   virtual const ACEXML_Char *getEncoding (void);
00094 
00095   /*
00096    * Get the systemId for the underlying CharStream
00097    */
00098   virtual const ACEXML_Char* getSystemId (void);
00099 
00100 protected:
00101 
00102   /** Read the next character as a normal character. Return -1 if EOF is
00103    *  reached, else return 0.
00104    */
00105   virtual int getchar_i (char& ch);
00106 
00107   /**
00108    * Peek @c offset bytes into the stream and return the character at @c
00109    * offset. If EOF is reached, return -1.
00110    */
00111   virtual int peekchar_i (off_t offset = 0);
00112 
00113 private:
00114 
00115 #if defined (ACE_USES_WCHAR)
00116   /**
00117    *  Read the next character from the stream taking into account the
00118    *  encoding of the file.
00119    */
00120   int get_i (ACEXML_Char& ch);
00121 
00122   /**
00123    *  Return the next character from the stream taking into account the
00124    *  encoding of the file. Subsequent call to get() returns this
00125    *  character.
00126    */
00127   int peek_i (void);
00128 
00129 #endif /* ACE_USES_WCHAR */
00130 
00131   ACEXML_Char*  filename_;
00132   ACEXML_Char*  encoding_;
00133   off_t         size_;
00134   ZZIP_FILE*    infile_;
00135   char          buf_[80];
00136   int           pos_;
00137   int           limit_;
00138 };
00139 
00140 #include /**/ "ace/post.h"
00141 
00142 #endif /* USE_ZZIP */
00143 
00144 #endif /* _ACEXML_ZIPCHARSTREAM_H_ */

Generated on Thu Nov 9 11:45:40 2006 for ACEXML by doxygen 1.3.6