]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/stream.h
Correct wxDataViewCtrl::IsExpanded and add test for it
[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
eb63011d
FM
32problems. Some Borland compilers refuse to work at all with them.
33@todo is this still true?
23114fe1 34
eb63011d
FM
35Besides, using @c std::iostream on Linux makes impossible to write programs that are
36binary compatible across different Linux distributions.
37
38Therefore, wxStreams have been added to wxWidgets so that an applications can
23114fe1
BP
39reliably compile and run on all supported platforms without dependence on a
40particular release of libg++.
41
eb63011d 42wxStream classes are divided in two main groups:
23114fe1
BP
43
44@li The core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
eb63011d
FM
45 wxFilterInputStream, wxFilterOutputStream
46@li The "IO" classes: wxSocketInputStream, wxSocketOutputStream,
47 wxFileInputStream, wxFileOutputStream, ...
23114fe1
BP
48
49wxStreamBase is the base definition of a stream. It defines, for example, the
eb63011d
FM
50API of OnSysRead(), OnSysWrite(), OnSysSeek() and OnSysTell(). These functions are
51really implemented by the "IO" classes.
52wxInputStream and wxOutputStream classes inherit from wxStreamBase and provide
53specialized methods for input and output.
23114fe1
BP
54
55wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
eb63011d
FM
56linked to a stream. One stream can have multiple stream buffers but one stream
57has always one autoinitialized stream buffer.
23114fe1 58
eb63011d
FM
59wxInputStream is the base class for read-only streams. It implements Read(),
60SeekI() (I for Input), and all read or IO generic related functions.
61wxOutputStream does the same thing for write-only streams.
23114fe1 62
eb63011d
FM
63wxFilterInputStream and wxFileterOutputStream are the base class definitions for
64stream filtering.
23114fe1 65Stream filtering means a stream which does no syscall but filters data which
eb63011d
FM
66are passed to it and then pass them to another stream.
67For example, wxZLibInputStream is an inline stream decompressor.
23114fe1
BP
68
69The "IO" classes implements the specific parts of the stream. This could be
eb63011d
FM
70nothing in the case of wxMemoryInputStream and wxMemoryOutputStream which base
71themselves on wxStreamBuffer.
72This could also be a simple link to the true syscall (for example read(...), write(...)).
23114fe1 73
30738aae 74
23114fe1
BP
75@section overview_stream_example Example
76
77Usage is simple. We can take the example of wxFileInputStream and here is some
78sample code:
79
80@code
81...
82// The constructor initializes the stream buffer and open the file descriptor
83// associated to the name of the file.
84wxFileInputStream in_stream("the_file_to_be_read");
85
86// Ok, read some bytes ... nb_datas is expressed in bytes.
87in_stream.Read(data, nb_datas);
88if (in_stream.LastError() != wxSTREAM_NOERROR) {
15b6757b
FM
89 // Oh oh, something bad happens.
90 // For a complete list, look into the documentation at wxStreamBase.
23114fe1 91}
36c9828f 92
23114fe1
BP
93// You can also inline all like this.
94if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {
15b6757b 95 // Do something.
23114fe1 96}
36c9828f 97
23114fe1
BP
98// You can also get the last number of bytes REALLY put into the buffer.
99size_t really_read = in_stream.LastRead();
36c9828f 100
3c4f71cc 101// Ok, moves to the beginning of the stream. SeekI returns the last position
23114fe1
BP
102// in the stream counted from the beginning.
103off_t old_position = in_stream.SeekI(0, wxFromBeginning);
36c9828f 104
23114fe1
BP
105// What is my current position ?
106off_t position = in_stream.TellI();
36c9828f 107
23114fe1
BP
108// wxFileInputStream will close the file descriptor on destruction.
109@endcode
36c9828f 110
23114fe1 111*/
36c9828f 112