IOStream.h
1/*
2 * Copyright (C) 2005-2012 Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_System_IOStream_h
30#define Pt_System_IOStream_h
31
32#include <Pt/System/Api.h>
33#include <Pt/System/IOBuffer.h>
34#include <Pt/IOStream.h>
35#include <cstddef>
36
37namespace Pt {
38
39namespace System {
40
48class IStream : public BasicIStream<char>
49{
50 public:
53 explicit IStream(std::size_t bufferSize = 8192, bool extend = false);
54
57 explicit IStream(IODevice& device, std::size_t bufferSize = 8192, bool extend = false);
58
61 {}
62
66 { return _buffer; }
67
71 { return _buffer.device(); }
72
75 void attach(IODevice& dev)
76 { _buffer.attach(dev); }
77
80 void detach()
81 { _buffer.detach(); }
82
85 void discard()
86 { _buffer.discard(); }
87
90 void reset()
91 { _buffer.reset(); }
92
93 private:
94 IOBuffer _buffer;
95};
96
104class OStream : public BasicOStream<char>
105{
106 public:
109 explicit OStream(std::size_t bufferSize = 8192, bool extend = false);
110
113 explicit OStream(IODevice& device, std::size_t bufferSize = 8192, bool extend = false);
114
117 {}
118
122 { return _buffer; }
123
127 { return _buffer.device(); }
128
131 void attach(IODevice& dev)
132 { _buffer.attach(dev); }
133
136 void detach()
137 { _buffer.detach(); }
138
141 void discard()
142 { _buffer.discard(); }
143
146 void reset()
147 { _buffer.reset(); }
148
149 private:
150 IOBuffer _buffer;
151};
152
166class IOStream : public BasicIOStream<char>
167{
168 public:
171 explicit IOStream(std::size_t bufferSize = 8192, bool extend = false);
172
175 explicit IOStream(IODevice& device, std::size_t bufferSize = 8192, bool extend = false);
176
179 {}
180
184 { return _buffer; }
185
189 { return _buffer.device(); }
190
193 void attach(IODevice& dev)
194 { _buffer.attach(dev); }
195
198 void detach()
199 { _buffer.detach(); }
200
203 void discard()
204 { _buffer.discard(); }
205
208 void reset()
209 { _buffer.reset(); }
210
211 private:
212 IOBuffer _buffer;
213};
214
215
216inline IStream::IStream(std::size_t bufferSize, bool extend)
217: BasicIStream<char>(0)
218, _buffer(bufferSize, extend)
219{
220 this->setBuffer(&_buffer);
221}
222
223
224inline IStream::IStream(IODevice& device, std::size_t bufferSize, bool extend)
225: BasicIStream<char>(0)
226, _buffer(device, bufferSize, extend)
227{
228 this->setBuffer(&_buffer);
229}
230
231
232inline OStream::OStream(std::size_t bufferSize, bool extend)
233: BasicOStream<char>(0)
234, _buffer(bufferSize, extend)
235{
236 this->setBuffer(&_buffer);
237}
238
239
240inline OStream::OStream(IODevice& device, std::size_t bufferSize, bool extend)
241: BasicOStream<char>(0)
242, _buffer(device, bufferSize, extend)
243{
244 this->setBuffer(&_buffer);
245}
246
247
248inline IOStream::IOStream(std::size_t bufferSize, bool extend)
249: BasicIOStream<char>(0)
250, _buffer(bufferSize, extend)
251{
252 this->setBuffer(&_buffer);
253}
254
255
256inline IOStream::IOStream(IODevice& device, std::size_t bufferSize, bool extend)
257: BasicIOStream<char>(0)
258, _buffer(device, bufferSize, extend)
259{
260 this->setBuffer(&_buffer);
261}
262
263} // namespace System
264
265} // namespace Pt
266
267#endif // Pt_System_IOStream_h
BasicIOStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:274
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:213
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:100
BasicIStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:225
BasicOStream(BasicStreamBuffer< char > *sb=0)
Definition IOStream.h:249
void setBuffer(BasicStreamBuffer< char > *sb)
Definition IOStream.h:152
Stream buffer for an IODevice.
Definition IOBuffer.h:60
Endpoint for I/O operations.
Definition IODevice.h:96
void discard()
Discards the buffer.
Definition IOStream.h:203
IODevice * device()
Returns the I/O device.
Definition IOStream.h:188
void attach(IODevice &dev)
Attach to I/O device.
Definition IOStream.h:193
IOBuffer & ioBuffer()
Returns the stream buffer.
Definition IOStream.h:183
~IOStream()
Destructor.
Definition IOStream.h:178
void detach()
Detach from I/O device.
Definition IOStream.h:198
void reset()
Discards and detaches.
Definition IOStream.h:208
IOStream(std::size_t bufferSize=8192, bool extend=false)
Construct with buffer size.
Definition IOStream.h:248
void discard()
Discards the buffer.
Definition IOStream.h:85
IODevice * device()
Returns the I/O device.
Definition IOStream.h:70
void attach(IODevice &dev)
Attach to I/O device.
Definition IOStream.h:75
IOBuffer & ioBuffer()
Returns the stream buffer.
Definition IOStream.h:65
IStream(std::size_t bufferSize=8192, bool extend=false)
Construct with buffer size.
Definition IOStream.h:216
void detach()
Detach from I/O device.
Definition IOStream.h:80
void reset()
Discards and detaches.
Definition IOStream.h:90
~IStream()
Destructor.
Definition IOStream.h:60
void discard()
Discards the buffer.
Definition IOStream.h:141
IODevice * device()
Returns the I/O device.
Definition IOStream.h:126
void attach(IODevice &dev)
Attach to I/O device.
Definition IOStream.h:131
IOBuffer & ioBuffer()
Returns the stream buffer.
Definition IOStream.h:121
void detach()
Detach from I/O device.
Definition IOStream.h:136
~OStream()
Destructor.
Definition IOStream.h:116
OStream(std::size_t bufferSize=8192, bool extend=false)
Construct with buffer size.
Definition IOStream.h:232
void reset()
Discards and detaches.
Definition IOStream.h:146
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33