2009-05-02 14:29:33 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/stdstream.h
|
|
|
|
// Purpose: Header of std::istream and std::ostream derived wrappers for
|
|
|
|
// wxInputStream and wxOutputStream
|
|
|
|
// Author: Jonathan Liu <net147@gmail.com>
|
|
|
|
// Created: 2009-05-02
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2009 Jonathan Liu
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_STDSTREAM_H_
|
|
|
|
#define _WX_STDSTREAM_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h" // wxUSE_STD_IOSTREAM
|
|
|
|
|
2010-07-12 18:50:51 -04:00
|
|
|
#if wxUSE_STREAMS && wxUSE_STD_IOSTREAM
|
2009-05-02 14:29:33 -04:00
|
|
|
|
2010-01-04 02:50:31 -05:00
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/stream.h"
|
2010-02-28 06:08:26 -05:00
|
|
|
#include "wx/ioswrap.h"
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// wxStdInputStreamBuffer
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStdInputStreamBuffer : public std::streambuf
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxStdInputStreamBuffer(wxInputStream& stream);
|
2012-11-20 07:49:03 -05:00
|
|
|
virtual ~wxStdInputStreamBuffer() { }
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual std::streambuf *setbuf(char *s, std::streamsize n);
|
|
|
|
virtual std::streampos seekoff(std::streamoff off,
|
|
|
|
std::ios_base::seekdir way,
|
|
|
|
std::ios_base::openmode which =
|
|
|
|
std::ios_base::in |
|
|
|
|
std::ios_base::out);
|
|
|
|
virtual std::streampos seekpos(std::streampos sp,
|
|
|
|
std::ios_base::openmode which =
|
|
|
|
std::ios_base::in |
|
|
|
|
std::ios_base::out);
|
|
|
|
virtual std::streamsize showmanyc();
|
|
|
|
virtual std::streamsize xsgetn(char *s, std::streamsize n);
|
|
|
|
virtual int underflow();
|
|
|
|
virtual int uflow();
|
|
|
|
virtual int pbackfail(int c = EOF);
|
|
|
|
|
2012-02-05 09:18:37 -05:00
|
|
|
// Special work around for VC8/9 (this bug was fixed in VC10 and later):
|
|
|
|
// these versions have non-standard _Xsgetn_s() that it being called from
|
|
|
|
// the stream code instead of xsgetn() and so our overridden implementation
|
|
|
|
// never actually gets used. To work around this, forward to it explicitly.
|
|
|
|
#if defined(__VISUALC8__) || defined(__VISUALC9__)
|
|
|
|
virtual std::streamsize
|
|
|
|
_Xsgetn_s(char *s, size_t WXUNUSED(size), std::streamsize n)
|
|
|
|
{
|
|
|
|
return xsgetn(s, n);
|
|
|
|
}
|
|
|
|
#endif // VC8 or VC9
|
|
|
|
|
2009-05-02 14:29:33 -04:00
|
|
|
wxInputStream& m_stream;
|
|
|
|
int m_lastChar;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// wxStdInputStream
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStdInputStream : public std::istream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxStdInputStream(wxInputStream& stream);
|
2012-11-20 07:49:03 -05:00
|
|
|
virtual ~wxStdInputStream() { }
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
wxStdInputStreamBuffer m_streamBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// wxStdOutputStreamBuffer
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStdOutputStreamBuffer : public std::streambuf
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxStdOutputStreamBuffer(wxOutputStream& stream);
|
2012-11-20 07:49:03 -05:00
|
|
|
virtual ~wxStdOutputStreamBuffer() { }
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual std::streambuf *setbuf(char *s, std::streamsize n);
|
|
|
|
virtual std::streampos seekoff(std::streamoff off,
|
|
|
|
std::ios_base::seekdir way,
|
|
|
|
std::ios_base::openmode which =
|
|
|
|
std::ios_base::in |
|
|
|
|
std::ios_base::out);
|
|
|
|
virtual std::streampos seekpos(std::streampos sp,
|
|
|
|
std::ios_base::openmode which =
|
|
|
|
std::ios_base::in |
|
|
|
|
std::ios_base::out);
|
|
|
|
virtual std::streamsize xsputn(const char *s, std::streamsize n);
|
|
|
|
virtual int overflow(int c);
|
|
|
|
|
|
|
|
wxOutputStream& m_stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// wxStdOutputStream
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_BASE wxStdOutputStream : public std::ostream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxStdOutputStream(wxOutputStream& stream);
|
2012-11-20 07:49:03 -05:00
|
|
|
virtual ~wxStdOutputStream() { }
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
wxStdOutputStreamBuffer m_streamBuffer;
|
|
|
|
};
|
|
|
|
|
2010-07-12 18:50:51 -04:00
|
|
|
#endif // wxUSE_STREAMS && wxUSE_STD_IOSTREAM
|
2009-05-02 14:29:33 -04:00
|
|
|
|
|
|
|
#endif // _WX_STDSTREAM_H_
|