]>
Commit | Line | Data |
---|---|---|
15b6757b | 1 | ///////////////////////////////////////////////////////////////////////////// |
23114fe1 | 2 | // Name: stream.h |
72a7c559 | 3 | // Purpose: stream classes overview |
15b6757b FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
15b6757b FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
880efa2a | 9 | /** |
36c9828f | 10 | |
831e1028 | 11 | @page overview_stream Stream Classes Overview |
23114fe1 | 12 | |
831e1028 | 13 | @tableofcontents |
23114fe1 | 14 | |
72a7c559 VZ |
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). | |
eb63011d | 22 | |
72a7c559 VZ |
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 | ||
831e1028 BP |
31 | |
32 | @section overview_stream_classes Stream Classes | |
23114fe1 | 33 | |
eb63011d | 34 | wxStream classes are divided in two main groups: |
23114fe1 BP |
35 | |
36 | @li The core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream, | |
eb63011d FM |
37 | wxFilterInputStream, wxFilterOutputStream |
38 | @li The "IO" classes: wxSocketInputStream, wxSocketOutputStream, | |
39 | wxFileInputStream, wxFileOutputStream, ... | |
673453e2 RR |
40 | @li Classes for reading text or binary data from a particular stream |
41 | such as wxTextInputStream, wxTextOutputStream, wxDataInputStream | |
42 | and wxDataOutputStream | |
23114fe1 BP |
43 | |
44 | wxStreamBase is the base definition of a stream. It defines, for example, the | |
eb63011d FM |
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. | |
23114fe1 BP |
49 | |
50 | wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer | |
eb63011d FM |
51 | linked to a stream. One stream can have multiple stream buffers but one stream |
52 | has always one autoinitialized stream buffer. | |
23114fe1 | 53 | |
eb63011d FM |
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. | |
23114fe1 | 57 | |
eb63011d FM |
58 | wxFilterInputStream and wxFileterOutputStream are the base class definitions for |
59 | stream filtering. | |
23114fe1 | 60 | Stream filtering means a stream which does no syscall but filters data which |
eb63011d FM |
61 | are passed to it and then pass them to another stream. |
62 | For example, wxZLibInputStream is an inline stream decompressor. | |
23114fe1 BP |
63 | |
64 | The "IO" classes implements the specific parts of the stream. This could be | |
eb63011d FM |
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(...)). | |
23114fe1 | 68 | |
30738aae | 69 | |
23114fe1 BP |
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) { | |
15b6757b FM |
84 | // Oh oh, something bad happens. |
85 | // For a complete list, look into the documentation at wxStreamBase. | |
23114fe1 | 86 | } |
36c9828f | 87 | |
23114fe1 BP |
88 | // You can also inline all like this. |
89 | if (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) { | |
15b6757b | 90 | // Do something. |
23114fe1 | 91 | } |
36c9828f | 92 | |
23114fe1 BP |
93 | // You can also get the last number of bytes REALLY put into the buffer. |
94 | size_t really_read = in_stream.LastRead(); | |
36c9828f | 95 | |
3c4f71cc | 96 | // Ok, moves to the beginning of the stream. SeekI returns the last position |
23114fe1 BP |
97 | // in the stream counted from the beginning. |
98 | off_t old_position = in_stream.SeekI(0, wxFromBeginning); | |
36c9828f | 99 | |
23114fe1 BP |
100 | // What is my current position ? |
101 | off_t position = in_stream.TellI(); | |
36c9828f | 102 | |
23114fe1 BP |
103 | // wxFileInputStream will close the file descriptor on destruction. |
104 | @endcode | |
36c9828f | 105 | |
23114fe1 | 106 | */ |