Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 896

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/tools/qbuffer.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QBuffer Class</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QBuffer Class Reference</h1>

<p>The QBuffer class is an I/O device that operates on a QByteArray.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qbuffer-h.html">qbuffer.h</a>&gt;</tt>
<p>Inherits <a href="qiodevice.html">QIODevice</a>.
<p><a href="qbuffer-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QBuffer"><b>QBuffer</b></a> ()</div></li>
<li><div class=fn><a href="#QBuffer-2"><b>QBuffer</b></a> ( QByteArray&nbsp;buf )</div></li>
<li><div class=fn><a href="#~QBuffer"><b>~QBuffer</b></a> ()</div></li>
<li><div class=fn>QByteArray <a href="#buffer"><b>buffer</b></a> () const</div></li>
<li><div class=fn>bool <a href="#setBuffer"><b>setBuffer</b></a> ( QByteArray&nbsp;buf )</div></li>
<li><div class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const&nbsp;char&nbsp;*&nbsp;p, Q_ULONG&nbsp;len )</div></li>
<li><div class=fn>Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const&nbsp;QByteArray&nbsp;&amp;&nbsp;data )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>




The QBuffer class is an I/O device that operates on a <a href="qbytearray.html">QByteArray</a>.
<p> QBuffer is used to read and write to a memory buffer. It is normally
used with a <a href="qtextstream.html">QTextStream</a> or a <a href="qdatastream.html">QDataStream</a>.  QBuffer has an
associated QByteArray which holds the buffer data. The <a href="qiodevice.html#size">size</a>() of the
buffer is automatically adjusted as data is written.
<p> The constructor <tt>QBuffer(QByteArray)</tt> creates a QBuffer with an
existing byte array.  The byte array can also be set with <a href="#setBuffer">setBuffer</a>().
Writing to the QBuffer will modify the original byte array because
QByteArray is <a href="shclass.html">explicitly shared.</a>
<p> Use <a href="qiodevice.html#open">open</a>() to open the buffer before use and to set the mode
(read-only, write-only, etc.).  <a href="qiodevice.html#close">close</a>() closes the buffer. The buffer
must be closed before reopening or calling setBuffer().
<p> A common way to use QBuffer is through <a href="qdatastream.html">QDataStream</a> or <a href="qtextstream.html">QTextStream</a>,
which have constructors that take a QBuffer parameter. For
convenience, there are also QDataStream and <a href="qtextstream.html">QTextStream</a> constructors
that take a <a href="qbytearray.html">QByteArray</a> parameter.  These constructors create and open
an internal QBuffer.
<p> Note that QTextStream can also operate on a <a href="qstring.html">QString</a> (a Unicode
string); a QBuffer cannot.
<p> You can also use QBuffer directly through the standard <a href="qiodevice.html">QIODevice</a>
functions <a href="qiodevice.html#readBlock">readBlock</a>(), <a href="#writeBlock">writeBlock</a>() <a href="qiodevice.html#readLine">readLine</a>(), <a href="qiodevice.html#at">at</a>(), <a href="qiodevice.html#getch">getch</a>(), <a href="qiodevice.html#putch">putch</a>() and
<a href="qiodevice.html#ungetch">ungetch</a>().
<p> <p>See also <a href="qfile.html">QFile</a>, <a href="qdatastream.html">QDataStream</a>, <a href="qtextstream.html">QTextStream</a>, <a href="qbytearray.html">QByteArray</a>, <a href="shclass.html">Shared Classes</a>, <a href="collection.html">Collection Classes</a> and <a href="io.html">Input/Output and Networking</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QBuffer"></a>QBuffer::QBuffer ()
</h3>
Constructs an empty buffer.

<h3 class=fn><a name="QBuffer-2"></a>QBuffer::QBuffer ( <a href="qbytearray.html">QByteArray</a>&nbsp;buf )
</h3>
Constructs a buffer that operates on <em>buf</em>.
If you open the buffer in write mode (<a href="qfile.html#open"><a href="qfile.html#open">IO_WriteOnly</a></a> or
<a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em>
will be modified.
<p> Example:
<pre>
    <a href="qcstring.html">QCString</a> str = "abc";
    QBuffer b( str );
    b.<a href="qiodevice.html#open">open</a>( IO_WriteOnly );
    b.<a href="qiodevice.html#at">at</a>( 3 ); // position at the 4th character (the terminating \0)
    b.<a href="#writeBlock">writeBlock</a>( "def", 4 ); // write "def" including the terminating \0
    b.<a href="qiodevice.html#close">close</a>();
    // Now, str == "abcdef" with a terminating \0
  </pre>
 
<p> <p>See also <a href="#setBuffer">setBuffer</a>().

<h3 class=fn><a name="~QBuffer"></a>QBuffer::~QBuffer ()
</h3>
Destroys the buffer.

<h3 class=fn><a href="qbytearray.html">QByteArray</a> <a name="buffer"></a>QBuffer::buffer () const
</h3>

<p> Returns this buffer's byte array.
<p> <p>See also <a href="#setBuffer">setBuffer</a>().

<h3 class=fn>bool <a name="setBuffer"></a>QBuffer::setBuffer ( <a href="qbytearray.html">QByteArray</a>&nbsp;buf )
</h3>
Replaces the buffer's contents with <em>buf</em>.
<p> This may not be done when <a href="qiodevice.html#isOpen">isOpen</a>() is TRUE.
<p> Note that if you open the buffer in write mode (<a href="qfile.html#open"><a href="qfile.html#open">IO_WriteOnly</a></a> or
<a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em> is also
modified because <a href="qbytearray.html">QByteArray</a> is an <a href="shclass.html#explicitly-shared">explicitly shared</a> class.
<p> <p>See also <a href="#buffer">buffer</a>(), <a href="qiodevice.html#open">open</a>() and <a href="qiodevice.html#close">close</a>().

<h3 class=fn>Q_LONG <a name="writeBlock"></a>QBuffer::writeBlock ( const&nbsp;char&nbsp;*&nbsp;p, Q_ULONG&nbsp;len )<tt> [virtual]</tt>
</h3>
<p> Writes <em>len</em> bytes from <em>p</em> into the buffer at the current index,
overwriting any characters there and extending the buffer if necessary.
Returns the number of bytes actually written.
<p> Returns -1 if an error occurred.
<p> <p>See also <a href="qiodevice.html#readBlock">readBlock</a>().

<p>Reimplemented from <a href="qiodevice.html#writeBlock">QIODevice</a>.
<h3 class=fn>Q_LONG <a name="writeBlock-2"></a>QBuffer::writeBlock ( const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;data )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> This convenience function takes <em>data</em> and is the same as calling
<tt>writeBlock( data.data(), data.size() )</tt>.
<p> 
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>