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