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