]> git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/stream.h
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / docs / doxygen / overviews / stream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: stream.h
3 // Purpose: stream classes overview
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10
11 @page overview_stream Stream Classes Overview
12
13 @tableofcontents
14
15 wxWidgets provides its own set of stream classes in order to support platforms
16 not providing standard C++ streams implementation and also to make it possible
17 to provide binary versions of wxWidgets application not depending on any
18 particular standard library version. The wxWidgets stream classes also provide
19 some functionality not available in the standard library such as support for
20 several compression formats and possibility to work with sockets or text
21 controls (for output only in the latter case).
22
23 Nevertheless wxWidgets programs can also use standard stream classes and are
24 encouraged to do so if the above considerations don't apply. Moreover,
25 wxStdInputStream and wxStdOutputStream classes are provided to provide a degree
26 of interoperability between the two and make it possible to use any wxWidgets
27 stream as a standard stream (the converse possibility to use a standard stream
28 as a wxWidgets stream is planned for a future release).
29
30
31
32 @section overview_stream_classes Stream Classes
33
34 wxStream classes are divided in two main groups:
35
36 @li The core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
37 wxFilterInputStream, wxFilterOutputStream
38 @li The "IO" classes: wxSocketInputStream, wxSocketOutputStream,
39 wxFileInputStream, wxFileOutputStream, ...
40 @li Classes for reading text or binary data from a particular stream
41 such as wxTextInputStream, wxTextOutputStream, wxDataInputStream
42 and wxDataOutputStream
43
44 wxStreamBase is the base definition of a stream. It defines, for example, the
45 API of OnSysRead(), OnSysWrite(), OnSysSeek() and OnSysTell(). These functions are
46 really implemented by the "IO" classes.
47 wxInputStream and wxOutputStream classes inherit from wxStreamBase and provide
48 specialized methods for input and output.
49
50 wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer
51 linked to a stream. One stream can have multiple stream buffers but one stream
52 has always one autoinitialized stream buffer.
53
54 wxInputStream is the base class for read-only streams. It implements Read(),
55 SeekI() (I for Input), and all read or IO generic related functions.
56 wxOutputStream does the same thing for write-only streams.
57
58 wxFilterInputStream and wxFileterOutputStream are the base class definitions for
59 stream filtering.
60 Stream filtering means a stream which does no syscall but filters data which
61 are passed to it and then pass them to another stream.
62 For example, wxZLibInputStream is an inline stream decompressor.
63
64 The "IO" classes implements the specific parts of the stream. This could be
65 nothing in the case of wxMemoryInputStream and wxMemoryOutputStream which base
66 themselves on wxStreamBuffer.
67 This could also be a simple link to the true syscall (for example read(...), write(...)).
68
69
70 @section overview_stream_example Example
71
72 Usage is simple. We can take the example of wxFileInputStream and here is some
73 sample code:
74
75 @code
76 ...
77 // The constructor initializes the stream buffer and open the file descriptor
78 // associated to the name of the file.
79 wxFileInputStream in_stream("the_file_to_be_read");
80
81 // Ok, read some bytes ... nb_datas is expressed in bytes.
82 in_stream.Read(data, nb_datas);
83 if (in_stream.LastError() != wxSTREAM_NOERROR) {
84 // Oh oh, something bad happens.
85 // For a complete list, look into the documentation at wxStreamBase.
86 }
87
88 // You can also inline all like this.
89 if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {
90 // Do something.
91 }
92
93 // You can also get the last number of bytes REALLY put into the buffer.
94 size_t really_read = in_stream.LastRead();
95
96 // Ok, moves to the beginning of the stream. SeekI returns the last position
97 // in the stream counted from the beginning.
98 off_t old_position = in_stream.SeekI(0, wxFromBeginning);
99
100 // What is my current position ?
101 off_t position = in_stream.TellI();
102
103 // wxFileInputStream will close the file descriptor on destruction.
104 @endcode
105
106 */