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