]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/stream.h
Don't take the previous paragraph style when deleting paragraph marker
[wxWidgets.git] / docs / doxygen / overviews / stream.h
CommitLineData
15b6757b
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: stream
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/*!
36c9828f 10
15b6757b 11 @page stream_overview wxStreams overview
36c9828f 12
15b6757b
FM
13 Classes: #wxStreamBase,
14 #wxStreamBuffer, #wxInputStream,
15 #wxOutputStream,
16 #wxFilterInputStream,
17 #wxFilterOutputStream
18 @b Purpose of wxStream
19 Standard C++ streams can cause problems on several platforms:
20 they work quite well in most cases, but in the multi-threaded case, for example,
21 they have many problems. Some Borland compilers refuse to work at all
22 with them and using iostreams on Linux makes writing programs that are
23 binary compatible across different Linux distributions, impossible.
24 Therefore, wxStreams have been added to wxWidgets so that applications can
25 reliably compile and run on all supported platforms without dependence on a
26 particular release of libg++.
27 wxStreams is divided in two main parts:
36c9828f
FM
28
29
15b6757b
FM
30 the core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
31 wxFilterIn/OutputStream
32 the "IO" classes: wxSocketIn/OutputStream, wxDataIn/OutputStream, wxFileIn/OutputStream, ...
36c9828f
FM
33
34
15b6757b 35 wxStreamBase is the base definition of a stream. It defines, for example,
36c9828f 36 the API of OnSysRead, OnSysWrite, OnSysSeek and OnSysTell. These functions
15b6757b
FM
37 are really implemented by the "IO" classes.
38 wxInputStream and wxOutputStream inherit from it.
39 wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
40 linked to a stream. One stream can have multiple stream buffers but one stream
41 have always one autoinitialized stream buffer.
42 wxInputStream is the base class for read-only streams. It implements Read,
43 SeekI (I for Input), and all read or IO generic related functions.
44 wxOutputStream does the same thing but it is for write-only streams.
45 wxFilterIn/OutputStream is the base class definition for stream filtering.
46 Stream filtering means a stream which does no syscall but filters data
47 which are passed to it and then pass them to another stream.
48 For example, wxZLibInputStream is an inline stream decompressor.
49 The "IO" classes implements the specific parts of the stream. This could be
50 nothing in the case of wxMemoryIn/OutputStream which bases itself on
51 wxStreamBuffer. This could also be a simple link to the a @true syscall
52 (for example read(...), write(...)).
53 @b Generic usage: an example
54 Usage is simple. We can take the example of wxFileInputStream and here is some sample
55 code:
36c9828f 56
15b6757b
FM
57 @code
58 ...
59 // The constructor initializes the stream buffer and open the file descriptor
60 // associated to the name of the file.
61 wxFileInputStream in_stream("the_file_to_be_read");
36c9828f 62
15b6757b
FM
63 // Ok, read some bytes ... nb_datas is expressed in bytes.
64 in_stream.Read(data, nb_datas);
65 if (in_stream.LastError() != wxSTREAM_NOERROR) {
66 // Oh oh, something bad happens.
67 // For a complete list, look into the documentation at wxStreamBase.
68 }
36c9828f 69
15b6757b
FM
70 // You can also inline all like this.
71 if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {
72 // Do something.
73 }
36c9828f 74
15b6757b
FM
75 // You can also get the last number of bytes REALLY put into the buffer.
76 size_t really_read = in_stream.LastRead();
36c9828f
FM
77
78 // Ok, moves to the beginning of the stream. SeekI returns the last position
15b6757b
FM
79 // in the stream counted from the beginning.
80 off_t old_position = in_stream.SeekI(0, wxFromBeginning);
36c9828f 81
15b6757b
FM
82 // What is my current position ?
83 off_t position = in_stream.TellI();
36c9828f 84
15b6757b
FM
85 // wxFileInputStream will close the file descriptor on destruction.
86 @endcode
36c9828f 87
15b6757b 88 */
36c9828f
FM
89
90