Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / ACEXML / common / FileCharStream.h
blobf1459976acfaf9c816726dc116c1990aec507ce8
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file FileCharStream.h
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
8 */
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)
18 #pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ACEXML/common/CharStream.h"
22 #include "ACEXML/common/Encoding.h"
24 /**
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
31 public:
32 /// Default constructor.
33 ACEXML_FileCharStream ();
35 /// Destructor
36 virtual ~ACEXML_FileCharStream ();
38 /// Open a file.
39 int open (const ACEXML_Char *name);
41 /**
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);
47 /**
48 * Returns the available ACEXML_Char in the buffer. -1
49 * if the object is not initialized properly.
51 virtual int available ();
53 /**
54 * Close this stream and release all resources used by it.
56 virtual int close ();
58 /**
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);
64 /**
65 * Read the next batch of ACEXML_Char strings
67 virtual int read (ACEXML_Char *str,
68 size_t len);
70 /**
71 * Determine the encoding of the file.
73 virtual int determine_encoding ();
76 /**
77 * Peek the next ACEXML_Char in the CharStream. Return the
78 * character if success, -1 if EOF is reached.
80 virtual int peek ();
82 /**
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 ();
97 private:
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
113 * character.
115 int peek_i ();
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_;
124 ACE_OFF_T size_;
125 FILE* infile_;
126 bool close_infile_;
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
130 // pushback.
131 ACEXML_Char peek_;
135 #include /**/ "ace/post.h"
137 #endif /* _ACEXML_FILECHARSTREAM_H_ */