]>
Commit | Line | Data |
---|---|---|
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 |
14 | wxWidgets provides its own set of stream classes in order to support platforms |
15 | not providing standard C++ streams implementation and also to make it possible | |
16 | to provide binary versions of wxWidgets application not depending on any | |
17 | particular standard library version. The wxWidgets stream classes also provide | |
18 | some functionality not available in the standard library such as support for | |
19 | several compression formats and possibility to work with sockets or text | |
20 | controls (for output only in the latter case). | |
eb63011d | 21 | |
72a7c559 VZ |
22 | Nevertheless wxWidgets programs can also use standard stream classes and are |
23 | encouraged to do so if the above considerations don't apply. Moreover, | |
24 | wxStdInputStream and wxStdOutputStream classes are provided to provide a degree | |
25 | of interoperability between the two and make it possible to use any wxWidgets | |
26 | stream as a standard stream (the converse possibility to use a standard stream | |
27 | as a wxWidgets stream is planned for a future release). | |
28 | ||
29 | ||
831e1028 BP |
30 | |
31 | @section overview_stream_classes Stream Classes | |
23114fe1 | 32 | |
eb63011d | 33 | wxStream 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 | |
43 | wxStreamBase is the base definition of a stream. It defines, for example, the | |
eb63011d FM |
44 | API of OnSysRead(), OnSysWrite(), OnSysSeek() and OnSysTell(). These functions are |
45 | really implemented by the "IO" classes. | |
46 | wxInputStream and wxOutputStream classes inherit from wxStreamBase and provide | |
47 | specialized methods for input and output. | |
23114fe1 BP |
48 | |
49 | wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer | |
eb63011d FM |
50 | linked to a stream. One stream can have multiple stream buffers but one stream |
51 | has always one autoinitialized stream buffer. | |
23114fe1 | 52 | |
eb63011d FM |
53 | wxInputStream is the base class for read-only streams. It implements Read(), |
54 | SeekI() (I for Input), and all read or IO generic related functions. | |
55 | wxOutputStream does the same thing for write-only streams. | |
23114fe1 | 56 | |
eb63011d FM |
57 | wxFilterInputStream and wxFileterOutputStream are the base class definitions for |
58 | stream filtering. | |
23114fe1 | 59 | Stream filtering means a stream which does no syscall but filters data which |
eb63011d FM |
60 | are passed to it and then pass them to another stream. |
61 | For example, wxZLibInputStream is an inline stream decompressor. | |
23114fe1 BP |
62 | |
63 | The "IO" classes implements the specific parts of the stream. This could be | |
eb63011d FM |
64 | nothing in the case of wxMemoryInputStream and wxMemoryOutputStream which base |
65 | themselves on wxStreamBuffer. | |
66 | This 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 | ||
71 | Usage is simple. We can take the example of wxFileInputStream and here is some | |
72 | sample 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. | |
78 | wxFileInputStream in_stream("the_file_to_be_read"); | |
79 | ||
80 | // Ok, read some bytes ... nb_datas is expressed in bytes. | |
81 | in_stream.Read(data, nb_datas); | |
82 | if (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. |
88 | if (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. |
93 | size_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. |
97 | off_t old_position = in_stream.SeekI(0, wxFromBeginning); | |
36c9828f | 98 | |
23114fe1 BP |
99 | // What is my current position ? |
100 | off_t position = in_stream.TellI(); | |
36c9828f | 101 | |
23114fe1 BP |
102 | // wxFileInputStream will close the file descriptor on destruction. |
103 | @endcode | |
36c9828f | 104 | |
23114fe1 | 105 | */ |