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>
8 // Copyright: (c) 2009 Jonathan Liu
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_STDSTREAM_H_
13 #define _WX_STDSTREAM_H_
15 #include "wx/defs.h" // wxUSE_STD_IOSTREAM
17 #if wxUSE_STREAMS && wxUSE_STD_IOSTREAM
20 #include "wx/stream.h"
21 #include "wx/ioswrap.h"
23 // ==========================================================================
24 // wxStdInputStreamBuffer
25 // ==========================================================================
27 class WXDLLIMPEXP_BASE wxStdInputStreamBuffer
: public std::streambuf
30 wxStdInputStreamBuffer(wxInputStream
& stream
);
31 virtual ~wxStdInputStreamBuffer() wxNOEXCEPT
{ }
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
=
40 virtual std::streampos
seekpos(std::streampos sp
,
41 std::ios_base::openmode which
=
44 virtual std::streamsize
showmanyc();
45 virtual std::streamsize
xsgetn(char *s
, std::streamsize n
);
46 virtual int underflow();
48 virtual int pbackfail(int c
= EOF
);
50 // Special work around for VC8/9 (this bug was fixed in VC10 and later):
51 // these versions have non-standard _Xsgetn_s() that it being called from
52 // the stream code instead of xsgetn() and so our overridden implementation
53 // never actually gets used. To work around this, forward to it explicitly.
54 #if defined(__VISUALC8__) || defined(__VISUALC9__)
55 virtual std::streamsize
56 _Xsgetn_s(char *s
, size_t WXUNUSED(size
), std::streamsize n
)
62 wxInputStream
& m_stream
;
66 // ==========================================================================
68 // ==========================================================================
70 class WXDLLIMPEXP_BASE wxStdInputStream
: public std::istream
73 wxStdInputStream(wxInputStream
& stream
);
74 virtual ~wxStdInputStream() wxNOEXCEPT
{ }
77 wxStdInputStreamBuffer m_streamBuffer
;
80 // ==========================================================================
81 // wxStdOutputStreamBuffer
82 // ==========================================================================
84 class WXDLLIMPEXP_BASE wxStdOutputStreamBuffer
: public std::streambuf
87 wxStdOutputStreamBuffer(wxOutputStream
& stream
);
88 virtual ~wxStdOutputStreamBuffer() wxNOEXCEPT
{ }
91 virtual std::streambuf
*setbuf(char *s
, std::streamsize n
);
92 virtual std::streampos
seekoff(std::streamoff off
,
93 std::ios_base::seekdir way
,
94 std::ios_base::openmode which
=
97 virtual std::streampos
seekpos(std::streampos sp
,
98 std::ios_base::openmode which
=
101 virtual std::streamsize
xsputn(const char *s
, std::streamsize n
);
102 virtual int overflow(int c
);
104 wxOutputStream
& m_stream
;
107 // ==========================================================================
109 // ==========================================================================
111 class WXDLLIMPEXP_BASE wxStdOutputStream
: public std::ostream
114 wxStdOutputStream(wxOutputStream
& stream
);
115 virtual ~wxStdOutputStream() wxNOEXCEPT
{ }
118 wxStdOutputStreamBuffer m_streamBuffer
;
121 #endif // wxUSE_STREAMS && wxUSE_STD_IOSTREAM
123 #endif // _WX_STDSTREAM_H_