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
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.27/include/rudiments/variablebuffer.h.html</title>
<meta name="Generator" content="Vim/6.2">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 2002 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a520f7">#ifndef RUDIMENTS_VARIABLEBUFFER_H</font>
<font color="#a520f7">#define RUDIMENTS_VARIABLEBUFFER_H</font>
<font color="#a520f7">#include </font><font color="#ff00ff"><rudiments/private/variablebufferincludes.h></font>
<font color="#0000ff">// The variablebuffer class can be used to store raw data of arbitrary length.</font>
<font color="#298a52"><b>class</b></font> variablebuffer {
<font color="#a52829"><b>public</b></font>:
variablebuffer(<font color="#298a52"><b>size_t</b></font> initialsize, <font color="#298a52"><b>size_t</b></font> increment);
variablebuffer(<font color="#298a52"><b>unsigned</b></font> <font color="#298a52"><b>char</b></font> *initialcontents,
<font color="#298a52"><b>size_t</b></font> initialsize, <font color="#298a52"><b>size_t</b></font> increment);
<font color="#0000ff">// Creates a new buffer of size "initialsize"</font>
<font color="#0000ff">// which will grow in chunks of size "increment".</font>
<font color="#0000ff">// The position at which the first write or append</font>
<font color="#0000ff">// will occur is initialized to 0.</font>
<font color="#298a52"><b>virtual</b></font> ~variablebuffer();
<font color="#298a52"><b>void</b></font> setPosition(<font color="#298a52"><b>size_t</b></font> pos);
<font color="#0000ff">// Sets the position at which the next read or write</font>
<font color="#0000ff">// will occur to "pos". If the position is set beyond</font>
<font color="#0000ff">// the end of the buffer, the buffer will grow but the</font>
<font color="#0000ff">// data between the current end of the buffer and the</font>
<font color="#0000ff">// new position will be undefined.</font>
<font color="#0000ff">// The write() and append() methods return a pointer to the</font>
<font color="#0000ff">// variablebuffer instance. This enables chaining:</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// sb->write(data1)->write(data2)->write(data3);</font>
<font color="#0000ff">// or</font>
<font color="#0000ff">// sb->append(data1)->append(data2)->append(data3);</font>
variablebuffer *write(<font color="#298a52"><b>const</b></font> <font color="#298a52"><b>unsigned</b></font> <font color="#298a52"><b>char</b></font> *data, <font color="#298a52"><b>size_t</b></font> size);
<font color="#0000ff">// Writes "data" to the variablebuffer at the current</font>
<font color="#0000ff">// position. If necessary, the buffer will grow to</font>
<font color="#0000ff">// accommodate the new data.</font>
variablebuffer *append(<font color="#298a52"><b>const</b></font> <font color="#298a52"><b>unsigned</b></font> <font color="#298a52"><b>char</b></font> *data, <font color="#298a52"><b>size_t</b></font> size);
<font color="#0000ff">// Appends "data" to the variablebuffer. The buffer</font>
<font color="#0000ff">// will grow to accommodate the new data.</font>
<font color="#298a52"><b>ssize_t</b></font> read(<font color="#298a52"><b>unsigned</b></font> <font color="#298a52"><b>char</b></font> *data, <font color="#298a52"><b>size_t</b></font> size);
<font color="#0000ff">// Reads "size" bytes from the variablebuffer at the</font>
<font color="#0000ff">// current position into "data". Also increments the</font>
<font color="#0000ff">// current position by "size" bytes.</font>
<font color="#298a52"><b>void</b></font> clear();
<font color="#0000ff">// Empties the variablebuffer.</font>
<font color="#298a52"><b>unsigned</b></font> <font color="#298a52"><b>char</b></font> *getBuffer();
<font color="#0000ff">// Returns the current data stored in the</font>
<font color="#0000ff">// variablebuffer.</font>
<font color="#298a52"><b>size_t</b></font> getSize();
<font color="#0000ff">// Returns the current amount of data stored</font>
<font color="#0000ff">// in the variablebuffer.</font>
<font color="#298a52"><b>size_t</b></font> getPosition();
<font color="#0000ff">// Returns the position in the buffer at which</font>
<font color="#0000ff">// the next write will occur.</font>
<font color="#298a52"><b>size_t</b></font> getEnd();
<font color="#0000ff">// Returns the position in the buffer at which</font>
<font color="#0000ff">// the next append will occur.</font>
<font color="#298a52"><b>size_t</b></font> getActualSize();
<font color="#0000ff">// Returns the actual size of the buffer which</font>
<font color="#0000ff">// may be larger than the value returned by</font>
<font color="#0000ff">// getSize() since the buffer grows in chunks.</font>
<font color="#a520f7"> #include </font><font color="#ff00ff"><rudiments/private/variablebuffer.h></font>
};
<font color="#a520f7">#endif</font>
</pre>
</body>
</html>
|