]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/stream.h
6a52ffd6e964df651a2c858acc7710c60df57edb
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: topic overview
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @page overview_stream wxStreams Overview
18 @li wxFilterInputStream
19 @li wxFilterOutputStream
21 @li @ref overview_stream_intro
22 @li @ref overview_stream_example
28 @section overview_stream_intro Introduction
30 Standard C++ streams can cause problems on several platforms: they work quite
31 well in most cases, but in the multi-threaded case, for example, they have many
32 problems. Some Borland compilers refuse to work at all with them and using
33 iostreams on Linux makes writing programs that are binary compatible across
34 different Linux distributions, impossible.
36 Therefore, wxStreams have been added to wxWidgets so that applications can
37 reliably compile and run on all supported platforms without dependence on a
38 particular release of libg++.
40 wxStreams is divided in two main parts:
42 @li The core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
43 wxFilterIn/OutputStream
44 @li The "IO" classes: wxSocketIn/OutputStream, wxDataIn/OutputStream,
45 wxFileIn/OutputStream, ...
47 wxStreamBase is the base definition of a stream. It defines, for example, the
48 API of OnSysRead, OnSysWrite, OnSysSeek and OnSysTell. These functions are
49 really implemented by the "IO" classes. wxInputStream and wxOutputStream
52 wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
53 linked to a stream. One stream can have multiple stream buffers but one stream
54 have always one autoinitialized stream buffer.
56 wxInputStream is the base class for read-only streams. It implements Read,
57 SeekI (I for Input), and all read or IO generic related functions.
58 wxOutputStream does the same thing but it is for write-only streams.
60 wxFilterIn/OutputStream is the base class definition for stream filtering.
61 Stream filtering means a stream which does no syscall but filters data which
62 are passed to it and then pass them to another stream. For example,
63 wxZLibInputStream is an inline stream decompressor.
65 The "IO" classes implements the specific parts of the stream. This could be
66 nothing in the case of wxMemoryIn/OutputStream which bases itself on
67 wxStreamBuffer. This could also be a simple link to the a true syscall (for
68 example read(...), write(...)).
71 @section overview_stream_example Example
73 Usage is simple. We can take the example of wxFileInputStream and here is some
78 // The constructor initializes the stream buffer and open the file descriptor
79 // associated to the name of the file.
80 wxFileInputStream in_stream("the_file_to_be_read");
82 // Ok, read some bytes ... nb_datas is expressed in bytes.
83 in_stream.Read(data, nb_datas);
84 if (in_stream.LastError() != wxSTREAM_NOERROR) {
85 // Oh oh, something bad happens.
86 // For a complete list, look into the documentation at wxStreamBase.
89 // You can also inline all like this.
90 if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {
94 // You can also get the last number of bytes REALLY put into the buffer.
95 size_t really_read = in_stream.LastRead();
97 // Ok, moves to the beginning of the stream. SeekI returns the last position
98 // in the stream counted from the beginning.
99 off_t old_position = in_stream.SeekI(0, wxFromBeginning);
101 // What is my current position ?
102 off_t position = in_stream.TellI();
104 // wxFileInputStream will close the file descriptor on destruction.