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