1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Stream Classes Overview</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Categories</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Stream Classes Overview </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_stream_classes">Stream Classes</a></li>
<li class="level1"><a href="#overview_stream_example">Example</a></li>
</ul>
</div>
<div class="textblock"><p>wxWidgets provides its own set of stream classes in order to support platforms not providing standard C++ streams implementation and also to make it possible to provide binary versions of wxWidgets application not depending on any particular standard library version.</p>
<p>The wxWidgets stream classes also provide some functionality not available in the standard library such as support for several compression formats and possibility to work with sockets or text controls (for output only in the latter case).</p>
<p>Nevertheless wxWidgets programs can also use standard stream classes and are encouraged to do so if the above considerations don't apply. Moreover, <a class="el" href="classwx_std_input_stream.html" title="wxStdInputStream is a std::istream derived stream which reads from a wxInputStream.">wxStdInputStream</a> and <a class="el" href="classwx_std_output_stream.html" title="wxStdOutputStream is a std::ostream derived stream which writes to a wxOutputStream.">wxStdOutputStream</a> classes are provided to provide a degree of interoperability between the two and make it possible to use any wxWidgets stream as a standard stream (the converse possibility to use a standard stream as a wxWidgets stream is planned for a future release).</p>
<h1><a class="anchor" id="overview_stream_classes"></a>
Stream Classes</h1>
<p>wxStream classes are divided in two main groups:</p>
<ul>
<li>The core: <a class="el" href="classwx_stream_base.html" title="This class is the base class of most stream related classes in wxWidgets.">wxStreamBase</a>, <a class="el" href="classwx_stream_buffer.html" title="wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer linked to a stream...">wxStreamBuffer</a>, <a class="el" href="classwx_input_stream.html" title="wxInputStream is an abstract base class which may not be used directly.">wxInputStream</a>, <a class="el" href="classwx_output_stream.html" title="wxOutputStream is an abstract base class which may not be used directly.">wxOutputStream</a>, <a class="el" href="classwx_filter_input_stream.html" title="A filter stream has the capability of a normal stream but it can be placed on top of another stream...">wxFilterInputStream</a>, <a class="el" href="classwx_filter_output_stream.html" title="A filter stream has the capability of a normal stream but it can be placed on top of another stream...">wxFilterOutputStream</a> </li>
<li>The "IO" classes: <a class="el" href="classwx_socket_input_stream.html" title="This class implements an input stream which reads data from a connected socket.">wxSocketInputStream</a>, <a class="el" href="classwx_socket_output_stream.html" title="This class implements an output stream which writes data from a connected socket.">wxSocketOutputStream</a>, <a class="el" href="classwx_file_input_stream.html" title="This class represents data read in from a file.">wxFileInputStream</a>, <a class="el" href="classwx_file_output_stream.html" title="This class represents data written to a file.">wxFileOutputStream</a>, ... </li>
<li>Classes for reading text or binary data from a particular stream such as <a class="el" href="classwx_text_input_stream.html" title="This class provides functions that reads text data using an input stream, allowing you to read text...">wxTextInputStream</a>, <a class="el" href="classwx_text_output_stream.html" title="This class provides functions that write text data using an output stream, allowing you to write text...">wxTextOutputStream</a>, <a class="el" href="classwx_data_input_stream.html" title="This class provides functions that read binary data types in a portable way.">wxDataInputStream</a> and <a class="el" href="classwx_data_output_stream.html" title="This class provides functions that write binary data types in a portable way.">wxDataOutputStream</a></li>
</ul>
<p><a class="el" href="classwx_stream_base.html" title="This class is the base class of most stream related classes in wxWidgets.">wxStreamBase</a> is the base definition of a stream. It defines, for example, the API of OnSysRead(), OnSysWrite(), OnSysSeek() and OnSysTell(). These functions are really implemented by the "IO" classes. <a class="el" href="classwx_input_stream.html" title="wxInputStream is an abstract base class which may not be used directly.">wxInputStream</a> and <a class="el" href="classwx_output_stream.html" title="wxOutputStream is an abstract base class which may not be used directly.">wxOutputStream</a> classes inherit from <a class="el" href="classwx_stream_base.html" title="This class is the base class of most stream related classes in wxWidgets.">wxStreamBase</a> and provide specialized methods for input and output.</p>
<p><a class="el" href="classwx_stream_buffer.html" title="wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer linked to a stream...">wxStreamBuffer</a> is a cache manager for <a class="el" href="classwx_stream_base.html" title="This class is the base class of most stream related classes in wxWidgets.">wxStreamBase</a>: it manages a stream buffer linked to a stream. One stream can have multiple stream buffers but one stream has always one autoinitialized stream buffer.</p>
<p><a class="el" href="classwx_input_stream.html" title="wxInputStream is an abstract base class which may not be used directly.">wxInputStream</a> is the base class for read-only streams. It implements Read(), SeekI() (I for Input), and all read or IO generic related functions. <a class="el" href="classwx_output_stream.html" title="wxOutputStream is an abstract base class which may not be used directly.">wxOutputStream</a> does the same thing for write-only streams.</p>
<p><a class="el" href="classwx_filter_input_stream.html" title="A filter stream has the capability of a normal stream but it can be placed on top of another stream...">wxFilterInputStream</a> and wxFileterOutputStream are the base class definitions for stream filtering. Stream filtering means a stream which does no syscall but filters data which are passed to it and then pass them to another stream. For example, wxZLibInputStream is an inline stream decompressor.</p>
<p>The "IO" classes implements the specific parts of the stream. This could be nothing in the case of <a class="el" href="classwx_memory_input_stream.html" title="This class allows to use all methods taking a wxInputStream reference to read in-memory data...">wxMemoryInputStream</a> and <a class="el" href="classwx_memory_output_stream.html" title="This class allows to use all methods taking a wxOutputStream reference to write to in-memory data...">wxMemoryOutputStream</a> which base themselves on <a class="el" href="classwx_stream_buffer.html" title="wxStreamBuffer is a cache manager for wxStreamBase: it manages a stream buffer linked to a stream...">wxStreamBuffer</a>. This could also be a simple link to the true syscall (for example read(...), write(...)).</p>
<h1><a class="anchor" id="overview_stream_example"></a>
Example</h1>
<p>Usage is simple. We can take the example of <a class="el" href="classwx_file_input_stream.html" title="This class represents data read in from a file.">wxFileInputStream</a> and here is some sample code:</p>
<div class="fragment"><div class="line">...</div>
<div class="line"><span class="comment">// The constructor initializes the stream buffer and open the file descriptor</span></div>
<div class="line"><span class="comment">// associated to the name of the file.</span></div>
<div class="line">wxFileInputStream in_stream(<span class="stringliteral">"the_file_to_be_read"</span>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// Ok, read some bytes ... nb_datas is expressed in bytes.</span></div>
<div class="line">in_stream.Read(data, nb_datas);</div>
<div class="line"><span class="keywordflow">if</span> (in_stream.LastError() != wxSTREAM_NOERROR) {</div>
<div class="line"> <span class="comment">// Oh oh, something bad happens.</span></div>
<div class="line"> <span class="comment">// For a complete list, look into the documentation at wxStreamBase.</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="comment">// You can also inline all like this.</span></div>
<div class="line"><span class="keywordflow">if</span> (in_stream.Read(data, nb_datas).LastError() != wxSTREAM_NOERROR) {</div>
<div class="line"> <span class="comment">// Do something.</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="comment">// You can also get the last number of bytes REALLY put into the buffer.</span></div>
<div class="line"><span class="keywordtype">size_t</span> really_read = in_stream.LastRead();</div>
<div class="line"></div>
<div class="line"><span class="comment">// Ok, moves to the beginning of the stream. SeekI returns the last position</span></div>
<div class="line"><span class="comment">// in the stream counted from the beginning.</span></div>
<div class="line">off_t old_position = in_stream.SeekI(0, wxFromBeginning);</div>
<div class="line"></div>
<div class="line"><span class="comment">// What is my current position ?</span></div>
<div class="line">off_t position = in_stream.TellI();</div>
<div class="line"></div>
<div class="line"><span class="comment">// wxFileInputStream will close the file descriptor on destruction.</span></div>
</div><!-- fragment --> </div></div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|