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

FileCharStream.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    FileCharStream.h
00006  *
00007  *  $Id: FileCharStream.h,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Nanbor Wang <nanbor@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef _ACEXML_FILECHARSTREAM_H_
00014 #define _ACEXML_FILECHARSTREAM_H_
00015 
00016 #include "ace/pre.h"
00017 #include "ACEXML/common/ACEXML_Export.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 #pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ACEXML/common/CharStream.h"
00024 #include "ACEXML/common/Encoding.h"
00025 #include "ace/streams.h"
00026 
00027 /**
00028  * @class ACEXML_FileCharStream FileCharStream.h "ACEXML/common/FileCharStream.h"
00029  *
00030  * An implementation of ACEXML_CharStream for reading input from a file.
00031  */
00032 class ACEXML_Export ACEXML_FileCharStream : public ACEXML_CharStream
00033 {
00034 public:
00035   /// Default constructor.
00036   ACEXML_FileCharStream (void);
00037 
00038   /// Destructor
00039   virtual ~ACEXML_FileCharStream (void);
00040 
00041   /// Open a file.
00042   int open (const ACEXML_Char *name);
00043 
00044   /**
00045    * Returns the available ACEXML_Char in the buffer.  -1
00046    * if the object is not initialized properly.
00047    */
00048   virtual int available (void);
00049 
00050   /**
00051    * Close this stream and release all resources used by it.
00052    */
00053   virtual int close (void);
00054 
00055   /**
00056    * Read the next ACEXML_Char.  Return -1 if we are not able to
00057    * return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed.
00058    */
00059   virtual int get (ACEXML_Char& ch);
00060 
00061   /**
00062    * Read the next batch of ACEXML_Char strings
00063    */
00064   virtual int read (ACEXML_Char *str,
00065                     size_t len);
00066 
00067   /**
00068    *  Determine the encoding of the file.
00069    */
00070   virtual int determine_encoding (void);
00071 
00072 
00073   /**
00074    * Peek the next ACEXML_Char in the CharStream.  Return the
00075    * character if success, -1 if EOF is reached.
00076    */
00077   virtual int peek (void);
00078 
00079   /**
00080    *  Resets the file pointer to the beginning of the stream.
00081    */
00082   virtual void rewind (void);
00083 
00084   /*
00085    * Get the character encoding for a byte stream or URI.
00086    */
00087   virtual const ACEXML_Char *getEncoding (void);
00088 
00089 protected:
00090 
00091   /** Read the next character as a normal character. Return -1 if EOF is
00092    *  reached, else return 0.
00093    */
00094   virtual int getchar_i (char& ch);
00095 
00096 private:
00097 
00098 #if defined (ACE_USES_WCHAR)
00099   /**
00100    *  Read the next character from the stream taking into account the
00101    *  encoding of the file.
00102    */
00103   int get_i (ACEXML_Char& ch);
00104 
00105   /**
00106    *  Read the next character from the stream taking into account the
00107    *  encoding of the file. Subsequent call to get() returns this
00108    *  character.
00109    */
00110   int peek_i (void);
00111 
00112 #endif /* ACE_USES_WCHAR */
00113 
00114   ACEXML_Char*  filename_;
00115   ACEXML_Char*  encoding_;
00116   off_t         size_;
00117   FILE*         infile_;
00118   // This is needed to ensure that we can implement a peek operation on a
00119   // UTF-16 encoded file. It is a bit hackish, but there is no other way of
00120   // implementing a peek() as the standard I/O FILE* guarantees only one
00121   // pushback.
00122   ACEXML_Char   peek_;
00123 };
00124 
00125 
00126 #include "ace/post.h"
00127 
00128 #endif /* _ACEXML_FILECHARSTREAM_H_ */

Generated on Mon Jun 16 13:23:21 2003 for ACEXML by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002