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>
7 // Copyright: (c) 2009 Jonathan Liu
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_STDSTREAM_H_
12 #define _WX_STDSTREAM_H_
14 #include "wx/defs.h" // wxUSE_STD_IOSTREAM
16 #if wxUSE_STREAMS && wxUSE_STD_IOSTREAM
19 #include "wx/stream.h"
20 #include "wx/ioswrap.h"
22 // ==========================================================================
23 // wxStdInputStreamBuffer
24 // ==========================================================================
26 class WXDLLIMPEXP_BASE wxStdInputStreamBuffer
: public std::streambuf
29 wxStdInputStreamBuffer(wxInputStream
& stream
);
30 virtual ~wxStdInputStreamBuffer() { }
33 virtual std::streambuf
*setbuf(char *s
, std::streamsize n
);
34 virtual std::streampos
seekoff(std::streamoff off
,
35 std::ios_base::seekdir way
,
36 std::ios_base::openmode which
=
39 virtual std::streampos
seekpos(std::streampos sp
,
40 std::ios_base::openmode which
=
43 virtual std::streamsize
showmanyc();
44 virtual std::streamsize
xsgetn(char *s
, std::streamsize n
);
45 virtual int underflow();
47 virtual int pbackfail(int c
= EOF
);
49 // Special work around for VC8/9 (this bug was fixed in VC10 and later):
50 // these versions have non-standard _Xsgetn_s() that it being called from
51 // the stream code instead of xsgetn() and so our overridden implementation
52 // never actually gets used. To work around this, forward to it explicitly.
53 #if defined(__VISUALC8__) || defined(__VISUALC9__)
54 virtual std::streamsize
55 _Xsgetn_s(char *s
, size_t WXUNUSED(size
), std::streamsize n
)
61 wxInputStream
& m_stream
;
65 // ==========================================================================
67 // ==========================================================================
69 class WXDLLIMPEXP_BASE wxStdInputStream
: public std::istream
72 wxStdInputStream(wxInputStream
& stream
);
73 virtual ~wxStdInputStream() { }
76 wxStdInputStreamBuffer m_streamBuffer
;
79 // ==========================================================================
80 // wxStdOutputStreamBuffer
81 // ==========================================================================
83 class WXDLLIMPEXP_BASE wxStdOutputStreamBuffer
: public std::streambuf
86 wxStdOutputStreamBuffer(wxOutputStream
& stream
);
87 virtual ~wxStdOutputStreamBuffer() { }
90 virtual std::streambuf
*setbuf(char *s
, std::streamsize n
);
91 virtual std::streampos
seekoff(std::streamoff off
,
92 std::ios_base::seekdir way
,
93 std::ios_base::openmode which
=
96 virtual std::streampos
seekpos(std::streampos sp
,
97 std::ios_base::openmode which
=
100 virtual std::streamsize
xsputn(const char *s
, std::streamsize n
);
101 virtual int overflow(int c
);
103 wxOutputStream
& m_stream
;
106 // ==========================================================================
108 // ==========================================================================
110 class WXDLLIMPEXP_BASE wxStdOutputStream
: public std::ostream
113 wxStdOutputStream(wxOutputStream
& stream
);
114 virtual ~wxStdOutputStream() { }
117 wxStdOutputStreamBuffer m_streamBuffer
;
120 #endif // wxUSE_STREAMS && wxUSE_STD_IOSTREAM
122 #endif // _WX_STDSTREAM_H_