3 //=============================================================================
5 * @file FileCharStream.h
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 //=============================================================================
11 #ifndef _ACEXML_FILECHARSTREAM_H_
12 #define _ACEXML_FILECHARSTREAM_H_
14 #include /**/ "ace/pre.h"
15 #include "ACEXML/common/ACEXML_Export.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ACEXML/common/CharStream.h"
22 #include "ACEXML/common/Encoding.h"
25 * @class ACEXML_FileCharStream
27 * An implementation of ACEXML_CharStream for reading input from a file.
29 class ACEXML_Export ACEXML_FileCharStream
: public ACEXML_CharStream
32 /// Default constructor.
33 ACEXML_FileCharStream ();
36 virtual ~ACEXML_FileCharStream ();
39 int open (const ACEXML_Char
*name
);
42 * Accept an already opened file. The stream does not
43 * assume ownership of open_file.
45 int use_stream (FILE* open_file
, const ACEXML_Char
*name
);
48 * Returns the available ACEXML_Char in the buffer. -1
49 * if the object is not initialized properly.
51 virtual int available ();
54 * Close this stream and release all resources used by it.
59 * Read the next ACEXML_Char. Return -1 if we are not able to
60 * return an ACEXML_Char, 0 if succees.
62 virtual int get (ACEXML_Char
& ch
);
65 * Read the next batch of ACEXML_Char strings
67 virtual int read (ACEXML_Char
*str
,
71 * Determine the encoding of the file.
73 virtual int determine_encoding ();
77 * Peek the next ACEXML_Char in the CharStream. Return the
78 * character if success, -1 if EOF is reached.
83 * Resets the file pointer to the beginning of the stream.
85 virtual void rewind ();
88 * Get the character encoding for the file.
90 virtual const ACEXML_Char
*getEncoding ();
93 * Get the systemId for the underlying CharStream
95 virtual const ACEXML_Char
* getSystemId ();
98 /** Read the next character as a normal character. Return -1 if EOF is
99 * reached, else return 0.
101 int getchar_i (char& ch
);
103 #if defined (ACE_USES_WCHAR)
105 * Read the next character from the stream taking into account the
106 * encoding of the file.
108 int get_i (ACEXML_Char
& ch
);
111 * Read the next character from the stream taking into account the
112 * encoding of the file. Subsequent call to get() returns this
117 #endif /* ACE_USES_WCHAR */
119 /// internal accept an already opened file.
120 int use_stream_i (FILE* open_file
, const ACEXML_Char
*name
);
122 ACEXML_Char
* filename_
;
123 ACEXML_Char
* encoding_
;
127 // This is needed to ensure that we can implement a peek operation on a
128 // UTF-16 encoded file. It is a bit hackish, but there is no other way of
129 // implementing a peek() as the standard I/O FILE* guarantees only one
135 #include /**/ "ace/post.h"
137 #endif /* _ACEXML_FILECHARSTREAM_H_ */