]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tstream.tex
- Updated gtk SWIGged files to SWIG 1.1 cvs level
[wxWidgets.git] / docs / latex / wx / tstream.tex
CommitLineData
55b7bba1
GL
1\section{Streams in wxWindows overview}\label{wxstreamoverview}
2
3Classes: \helpref{wxStreamBase}{wxstreambase},
4 \helpref{wxStreamBuffer}{wxstreambuffer}, \helpref{wxInputStream}{wxinputstream},
5 \helpref{wxOutputStream}{wxoutputstream},
6 \helpref{wxFilterInputStream}{wxfilterinputstream},
7 \helpref{wxFilterOutputStream}{wxfilteroutputstream}
8
9\wxheading{Purpose of wxStream}
10
4130b487 11We went into troubles with C++ std streams on several platforms:
55b7bba1 12they react quite well in most cases, but in multi-threaded case, for example,
4130b487
RR
13they have many problems. Some Borland Compilers refuse to work at all
14with them and using iostreams on Linux makes writing programs, that are
15binary compatible across different Linux distributions, impossible.
55b7bba1 16
4130b487
RR
17Therefore, wxStreams have been added to wxWindows because an application should
18compile and run on all supported platforms and we don't want users depend on release
55b7bba1
GL
19X.XX of libg++ or some other compiler to run the program.
20
21wxStreams is divided in two main parts:
22\begin{enumerate}\itemsep=0pt
23\item the core: wxStreamBase, wxStreamBuffer, wxInputStream, wxOutputStream,
24wxFilterIn/OutputStream
25\item the "IO" classes: wxSocketIn/OutputStream, wxDataIn/OutputStream, wxFileIn/OutputStream, ...
26\end{enumerate}
27
28wxStreamBase is the base definition of a stream. It defines, for example,
29the API of OnSysRead, OnSysWrite, OnSysSeek and OnSysTell. These functions are
30are really implemented by the "IO" classes.
31wxInputStream and wxOutputStream inherit from it.
32
33wxStreamBuffer is a cache manager for wxStreamBase (it manages a stream buffer
34linked to a stream). One stream can have multiple stream buffers but one stream
35have always one autoinitialized stream buffer.
36
37wxInputStream is the base class for read-only streams. It implements Read,
38SeekI (I for Input), and all read or IO generic related functions.
39wxOutputStream does the same thing but it is for write-only streams.
40
41wxFilterIn/OutputStream is base class definition for stream filtering.
42I mean by stream filtering, a stream which does no syscall but filter datas
43which are passed to it and then pass them to another stream.
44For example, wxZLibInputStream is an inline stream decompressor.
45
46The "IO" classes implements the specific parts of the stream. This could be
47nothing in the case of wxMemoryIn/OutputStream which bases itself on
48wxStreamBuffer. This could also be a simple link to the a true syscall
49(for example read(...), write(...)).
50
51\wxheading{Generic usage: an example}
52
53About its usage, it's simple. We can take the example of wxFileInputStream and here is a sample
54code:
55
56\begin{verbatim}
57 ...
58 // The constructor initializes the stream buffer and open the file descriptor
59 // associated to the name of the file.
4130b487 60 wxFileInputStream in_stream("the_file_to_be_read");
55b7bba1 61
4130b487
RR
62 // Ok, read some bytes ... nb_datas is expressed in bytes.
63 in_stream.Read(data, nb_datas);
64 if (in_stream.LastError() != wxStream_NOERROR) {
55b7bba1
GL
65 // Oh oh, something bad happens.
66 // For a complete list, look into the documentation at wxStreamBase.
67 }
68
69 // You can also inline all like this.
4130b487 70 if (in_stream.Read(data, nb_datas).LastError() != wxStream_NOERROR) {
55b7bba1
GL
71 // Do something.
72 }
73
74 // You can also get the last number of bytes REALLY put into the buffer.
4130b487 75 size_t really_read = in_stream.LastRead();
55b7bba1
GL
76
77 // Ok, moves to the beginning of the stream. SeekI returns the last position
78 // in the stream counted from the beginning.
4130b487 79 off_t old_position = in_stream.SeekI(0, wxFromBeginning);
55b7bba1
GL
80
81 // What is my current position ?
4130b487 82 off_t position = in_stream.TellI();
55b7bba1
GL
83
84 // wxFileInputStream will close the file descriptor on the destruction.
85\end{verbatim}
86
87\wxheading{Compatibility with c++ stream}
88
89As I said previously, we could add a filter stream so it takes an istream
90argument and builds a wxInputStream from it: I don't think it should
91be difficult to implement it and it may be available in the fix of wxWindows 2.0.
22d6efa8 92