]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/stdstream.h
making sure TextMatrix is always identity, there were strange artifacts sometimes...
[wxWidgets.git] / interface / wx / stdstream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stdstream.h
3 // Purpose: interface of wxStdInputStream, wxStdInputStreamBuffer,
4 // wxStdOutputStream, wxStdOutputStreamBuffer
5 // Author: Jonathan Liu <net147@gmail.com>
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Jonathan Liu
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 /**
12 @class wxStdInputStreamBuffer
13
14 wxStdInputStreamBuffer is a std::streambuf derived stream buffer which
15 reads from a wxInputStream.
16
17 Example:
18 @code
19 wxFFileInputStream file("input.txt.gz");
20 wxZlibInputStream gzipInput(file, wxZLIB_GZIP);
21 wxStdInputStreamBuffer gzipStreamBuffer(gzipInput);
22
23 // redirect std::cin to read from compressed file
24 std::streambuf* streamBufferOld = std::cin.rdbuf(&gzipStreamBuffer);
25
26 // prompt for integer
27 int number;
28 std::cout << "Enter an integer: " << std::flush;
29 std::cin >> number;
30 std::cout << std::endl;
31 std::cout << "You entered the integer " << number << "." << std::endl;
32
33 // restore std::cin
34 std::cin.rdbuf(streamBufferOld);
35 @endcode
36
37 @library{wxbase}
38 @category{streams}
39
40 @see wxInputStream, wxStdInputStream
41 */
42 class wxStdInputStreamBuffer : public std::streambuf
43 {
44 public:
45 /**
46 Creates a std::steambuf derived stream buffer which reads from a
47 wxInputStream.
48
49 @param stream
50 Stream to read from.
51 */
52 wxStdInputStreamBuffer(wxInputStream& stream);
53
54 /**
55 Destructor.
56 */
57 virtual ~wxStdInputStreamBuffer() { }
58 };
59
60 /**
61 @class wxStdInputStream
62
63 wxStdInputStream is a std::istream derived stream which reads from
64 a wxInputStream.
65
66 Example:
67 @code
68 wxFFileInputStream file("words.txt");
69 wxStdInputStream in(file);
70 std::vector<std::string> words;
71
72 // read words from words.txt
73 std::copy(std::istream_iterator<std::string>(in),
74 std::istream_iterator<std::string>(),
75 std::back_inserter(words));
76
77 // sort and remove duplicates
78 std::sort(words.begin(), words.end());
79 words.resize(std::unique(words.begin(), words.end()) - words.begin());
80
81 // print words
82 std::copy(words.begin(), words.end(),
83 std::ostream_iterator<std::string>(std::cout, "\n"));
84 @endcode
85
86 @library{wxbase}
87 @category{streams}
88
89 @see wxInputStream, wxStdInputStreamBuffer
90 */
91 class wxStdInputStream : public std::istream
92 {
93 public:
94 /**
95 Creates a std::istream derived stream which reads from a
96 wxInputStream.
97
98 @param stream
99 Stream to read from.
100 */
101 wxStdInputStream(wxInputStream& stream);
102
103 /**
104 Destructor.
105 */
106 virtual ~wxStdInputStream() { }
107 };
108
109 /**
110 @class wxStdOutputStreamBuffer
111
112 wxStdOutputStreamBuffer is a std::streambuf derived stream buffer which
113 writes to a wxOutputStream.
114
115 Example:
116 @code
117 wxFFileOutputStream file("cout.txt.gz");
118 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
119 wxStdOutputStreamBuffer gzipStreamBuffer(gzipOutput);
120
121 // redirect std::cout to cout.txt.gz using GZIP compression
122 std::streambuf* streamBufferOld = std::cout.rdbuf(&gzipStreamBuffer);
123
124 // write to std::cout
125 std::cout << "Hello world!" << std::endl;
126
127 // restore std::cout
128 std::cout.rdbuf(streamBufferOld);
129 @endcode
130
131 @library{wxbase}
132 @category{streams}
133
134 @see wxOutputStream, wxStdOutputStream
135 */
136 class wxStdOutputStreamBuffer : public std::streambuf
137 {
138 public:
139 /**
140 Creates a std::steambuf derived stream buffer which writes to a
141 wxOutputStream.
142
143 @param stream
144 Stream to write to.
145 */
146 wxStdOutputStreamBuffer(wxOutputStream& stream);
147
148 /**
149 Destructor.
150 */
151 virtual ~wxStdOutputStreamBuffer() { }
152 };
153
154 /**
155 @class wxStdOutputStream
156
157 wxStdOutputStream is a std::ostream derived stream which writes to a
158 wxOutputStream.
159
160 Example:
161 @code
162 wxFFileOutputStream file("out.txt.gz");
163 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
164 wxStdOutputStream out(gzipOutput);
165
166 out << "Hello world!" << std::endl;
167 @endcode
168
169 @library{wxbase}
170 @category{streams}
171
172 @see wxOutputStream, wxStdOutputStreamBuffer
173 */
174 class wxStdOutputStream : public std::ostream
175 {
176 public:
177 /**
178 Creates a std::ostream derived stream which writes to a
179 wxOutputStream.
180
181 @param stream
182 Stream to write to.
183 */
184 wxStdOutputStream(wxOutputStream& stream);
185
186 /**
187 Destructor.
188 */
189 virtual ~wxStdOutputStream() { }
190 };