File: stdstream.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (189 lines) | stat: -rw-r--r-- 4,665 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/////////////////////////////////////////////////////////////////////////////
// Name:        stdstream.h
// Purpose:     interface of wxStdInputStream, wxStdInputStreamBuffer,
//              wxStdOutputStream, wxStdOutputStreamBuffer
// Author:      Jonathan Liu <net147@gmail.com>
// Copyright:   (c) 2009 Jonathan Liu
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @class wxStdInputStreamBuffer

    wxStdInputStreamBuffer is a std::streambuf derived stream buffer which
    reads from a wxInputStream.

    Example:
    @code
    wxFFileInputStream file("input.txt.gz");
    wxZlibInputStream gzipInput(file, wxZLIB_GZIP);
    wxStdInputStreamBuffer gzipStreamBuffer(gzipInput);

    // redirect std::cin to read from compressed file
    std::streambuf* streamBufferOld = std::cin.rdbuf(&gzipStreamBuffer);

    // prompt for integer
    int number;
    std::cout << "Enter an integer: " << std::flush;
    std::cin >> number;
    std::cout << std::endl;
    std::cout << "You entered the integer " << number << "." << std::endl;

    // restore std::cin
    std::cin.rdbuf(streamBufferOld);
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxInputStream, wxStdInputStream
*/
class wxStdInputStreamBuffer : public std::streambuf
{
public:
    /**
        Creates a std::steambuf derived stream buffer which reads from a
        wxInputStream.

        @param stream
            Stream to read from.
    */
    wxStdInputStreamBuffer(wxInputStream& stream);

    /**
        Destructor.
    */
    virtual ~wxStdInputStreamBuffer() { }
};

/**
    @class wxStdInputStream

    wxStdInputStream is a std::istream derived stream which reads from
    a wxInputStream.

    Example:
    @code
    wxFFileInputStream file("words.txt");
    wxStdInputStream in(file);
    std::vector<std::string> words;

    // read words from words.txt
    std::copy(std::istream_iterator<std::string>(in),
              std::istream_iterator<std::string>(),
              std::back_inserter(words));

    // sort and remove duplicates
    std::sort(words.begin(), words.end());
    words.resize(std::unique(words.begin(), words.end()) - words.begin());

    // print words
    std::copy(words.begin(), words.end(),
              std::ostream_iterator<std::string>(std::cout, "\n"));
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxInputStream, wxStdInputStreamBuffer
*/
class wxStdInputStream : public std::istream
{
public:
    /**
        Creates a std::istream derived stream which reads from a
        wxInputStream.

        @param stream
            Stream to read from.
    */
    wxStdInputStream(wxInputStream& stream);

    /**
        Destructor.
    */
    virtual ~wxStdInputStream() { }
};

/**
    @class wxStdOutputStreamBuffer

    wxStdOutputStreamBuffer is a std::streambuf derived stream buffer which
    writes to a wxOutputStream.

    Example:
    @code
    wxFFileOutputStream file("cout.txt.gz");
    wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
    wxStdOutputStreamBuffer gzipStreamBuffer(gzipOutput);

    // redirect std::cout to cout.txt.gz using GZIP compression
    std::streambuf* streamBufferOld = std::cout.rdbuf(&gzipStreamBuffer);

    // write to std::cout
    std::cout << "Hello world!" << std::endl;

    // restore std::cout
    std::cout.rdbuf(streamBufferOld);
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxOutputStream, wxStdOutputStream
*/
class wxStdOutputStreamBuffer : public std::streambuf
{
public:
    /**
        Creates a std::steambuf derived stream buffer which writes to a
        wxOutputStream.

        @param stream
            Stream to write to.
    */
    wxStdOutputStreamBuffer(wxOutputStream& stream);

    /**
        Destructor.
    */
    virtual ~wxStdOutputStreamBuffer() { }
};

/**
    @class wxStdOutputStream

    wxStdOutputStream is a std::ostream derived stream which writes to a
    wxOutputStream.

    Example:
    @code
    wxFFileOutputStream file("out.txt.gz");
    wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
    wxStdOutputStream out(gzipOutput);

    out << "Hello world!" << std::endl;
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxOutputStream, wxStdOutputStreamBuffer
*/
class wxStdOutputStream : public std::ostream
{
public:
    /**
        Creates a std::ostream derived stream which writes to a
        wxOutputStream.

        @param stream
            Stream to write to.
    */
    wxStdOutputStream(wxOutputStream& stream);

    /**
        Destructor.
    */
    virtual ~wxStdOutputStream() { }
};