File: stdstream.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (122 lines) | stat: -rw-r--r-- 4,397 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/////////////////////////////////////////////////////////////////////////////
// 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
// Copyright:   (c) 2009 Jonathan Liu
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_STDSTREAM_H_
#define _WX_STDSTREAM_H_

#include "wx/defs.h"    // wxUSE_STD_IOSTREAM

#if wxUSE_STREAMS && wxUSE_STD_IOSTREAM

#include "wx/defs.h"
#include "wx/stream.h"
#include "wx/ioswrap.h"

// ==========================================================================
// wxStdInputStreamBuffer
// ==========================================================================

class WXDLLIMPEXP_BASE wxStdInputStreamBuffer : public std::streambuf
{
public:
    wxStdInputStreamBuffer(wxInputStream& stream);
    virtual ~wxStdInputStreamBuffer() { }

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);

    // 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

    wxInputStream& m_stream;
    int m_lastChar;
};

// ==========================================================================
// wxStdInputStream
// ==========================================================================

class WXDLLIMPEXP_BASE wxStdInputStream : public std::istream
{
public:
    wxStdInputStream(wxInputStream& stream);
    virtual ~wxStdInputStream() { }

protected:
    wxStdInputStreamBuffer m_streamBuffer;
};

// ==========================================================================
// wxStdOutputStreamBuffer
// ==========================================================================

class WXDLLIMPEXP_BASE wxStdOutputStreamBuffer : public std::streambuf
{
public:
    wxStdOutputStreamBuffer(wxOutputStream& stream);
    virtual ~wxStdOutputStreamBuffer() { }

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);
    virtual ~wxStdOutputStream() { }

protected:
    wxStdOutputStreamBuffer m_streamBuffer;
};

#endif // wxUSE_STREAMS && wxUSE_STD_IOSTREAM

#endif // _WX_STDSTREAM_H_