]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/stdstream.h | |
3 | // Purpose: Header of std::istream and std::ostream derived wrappers for | |
4 | // wxInputStream and wxOutputStream | |
5 | // Author: Jonathan Liu <net147@gmail.com> | |
6 | // Created: 2009-05-02 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2009 Jonathan Liu | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_STDSTREAM_H_ | |
13 | #define _WX_STDSTREAM_H_ | |
14 | ||
15 | #include "wx/defs.h" // wxUSE_STD_IOSTREAM | |
16 | ||
17 | #if wxUSE_STD_IOSTREAM | |
18 | ||
19 | #include <iosfwd> | |
20 | #include "wx/defs.h" | |
21 | #include "wx/stream.h" | |
22 | ||
23 | // ========================================================================== | |
24 | // wxStdInputStreamBuffer | |
25 | // ========================================================================== | |
26 | ||
27 | class WXDLLIMPEXP_BASE wxStdInputStreamBuffer : public std::streambuf | |
28 | { | |
29 | public: | |
30 | wxStdInputStreamBuffer(wxInputStream& stream); | |
31 | virtual ~wxStdInputStreamBuffer() { } | |
32 | ||
33 | protected: | |
34 | virtual std::streambuf *setbuf(char *s, std::streamsize n); | |
35 | virtual std::streampos seekoff(std::streamoff off, | |
36 | std::ios_base::seekdir way, | |
37 | std::ios_base::openmode which = | |
38 | std::ios_base::in | | |
39 | std::ios_base::out); | |
40 | virtual std::streampos seekpos(std::streampos sp, | |
41 | std::ios_base::openmode which = | |
42 | std::ios_base::in | | |
43 | std::ios_base::out); | |
44 | virtual std::streamsize showmanyc(); | |
45 | virtual std::streamsize xsgetn(char *s, std::streamsize n); | |
46 | virtual int underflow(); | |
47 | virtual int uflow(); | |
48 | virtual int pbackfail(int c = EOF); | |
49 | ||
50 | wxInputStream& m_stream; | |
51 | int m_lastChar; | |
52 | }; | |
53 | ||
54 | // ========================================================================== | |
55 | // wxStdInputStream | |
56 | // ========================================================================== | |
57 | ||
58 | class WXDLLIMPEXP_BASE wxStdInputStream : public std::istream | |
59 | { | |
60 | public: | |
61 | wxStdInputStream(wxInputStream& stream); | |
62 | virtual ~wxStdInputStream() { } | |
63 | ||
64 | protected: | |
65 | wxStdInputStreamBuffer m_streamBuffer; | |
66 | }; | |
67 | ||
68 | // ========================================================================== | |
69 | // wxStdOutputStreamBuffer | |
70 | // ========================================================================== | |
71 | ||
72 | class WXDLLIMPEXP_BASE wxStdOutputStreamBuffer : public std::streambuf | |
73 | { | |
74 | public: | |
75 | wxStdOutputStreamBuffer(wxOutputStream& stream); | |
76 | virtual ~wxStdOutputStreamBuffer() { } | |
77 | ||
78 | protected: | |
79 | virtual std::streambuf *setbuf(char *s, std::streamsize n); | |
80 | virtual std::streampos seekoff(std::streamoff off, | |
81 | std::ios_base::seekdir way, | |
82 | std::ios_base::openmode which = | |
83 | std::ios_base::in | | |
84 | std::ios_base::out); | |
85 | virtual std::streampos seekpos(std::streampos sp, | |
86 | std::ios_base::openmode which = | |
87 | std::ios_base::in | | |
88 | std::ios_base::out); | |
89 | virtual std::streamsize xsputn(const char *s, std::streamsize n); | |
90 | virtual int overflow(int c); | |
91 | ||
92 | wxOutputStream& m_stream; | |
93 | }; | |
94 | ||
95 | // ========================================================================== | |
96 | // wxStdOutputStream | |
97 | // ========================================================================== | |
98 | ||
99 | class WXDLLIMPEXP_BASE wxStdOutputStream : public std::ostream | |
100 | { | |
101 | public: | |
102 | wxStdOutputStream(wxOutputStream& stream); | |
103 | virtual ~wxStdOutputStream() { } | |
104 | ||
105 | protected: | |
106 | wxStdOutputStreamBuffer m_streamBuffer; | |
107 | }; | |
108 | ||
109 | #endif // wxUSE_STD_IOSTREAM | |
110 | ||
111 | #endif // _WX_STDSTREAM_H_ |