File: variablebuffer.h.html

package info (click to toggle)
rudiments 0.32-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,932 kB
  • ctags: 3,047
  • sloc: cpp: 23,013; sh: 7,769; ansic: 1,769; makefile: 1,057; xml: 169; perl: 19
file content (127 lines) | stat: -rw-r--r-- 10,365 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/variablebuffer.h.html</title>
<meta name="Generator" content="Vim/7.0">
<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="#a020f0">#ifndef RUDIMENTS_VARIABLEBUFFER_H</font>
<font color="#a020f0">#define RUDIMENTS_VARIABLEBUFFER_H</font>

<font color="#a020f0">#include </font><font color="#ff00ff">&lt;rudiments/private/variablebufferincludes.h&gt;</font>

<font color="#0000ff">// The variablebuffer class can be used to store raw data of arbitrary length.</font>

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>

<font color="#2e8b57"><b>class</b></font> variablebufferprivate;

<font color="#2e8b57"><b>class</b></font> variablebuffer {
        <font color="#a52a2a"><b>public</b></font>:
                        variablebuffer(<font color="#2e8b57"><b>size_t</b></font> initialsize, <font color="#2e8b57"><b>size_t</b></font> increment);
                        variablebuffer(<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *initialcontents,
                                        <font color="#2e8b57"><b>size_t</b></font> initialsize, <font color="#2e8b57"><b>size_t</b></font> increment);
                        <font color="#0000ff">// Creates a new buffer of size &quot;initialsize&quot;</font>
                        <font color="#0000ff">// which will grow in chunks of size &quot;increment&quot;.</font>
                        <font color="#0000ff">// The position at which the first write or append</font>
                        <font color="#0000ff">// will occur is initialized to 0.</font>
                        variablebuffer(<font color="#2e8b57"><b>const</b></font> variablebuffer &amp;v);
                variablebuffer  &amp;<font color="#a52a2a"><b>operator</b></font>=(<font color="#2e8b57"><b>const</b></font> variablebuffer &amp;v);
                <font color="#2e8b57"><b>virtual</b></font>       ~variablebuffer();

                <font color="#2e8b57"><b>void</b></font>  setPosition(<font color="#2e8b57"><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 &quot;pos&quot;.  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-&gt;write(data1)-&gt;write(data2)-&gt;write(data3);</font>
                <font color="#0000ff">//            or</font>
                <font color="#0000ff">//    sb-&gt;append(data1)-&gt;append(data2)-&gt;append(data3);</font>
                variablebuffer  *write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *data, <font color="#2e8b57"><b>size_t</b></font> size);
                variablebuffer  *write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
                variablebuffer  *write(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string, <font color="#2e8b57"><b>size_t</b></font> size);
                variablebuffer  *write(<font color="#2e8b57"><b>char</b></font> character);
                variablebuffer  *write(<font color="#2e8b57"><b>int16_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>int32_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>int64_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> character);
                variablebuffer  *write(<font color="#2e8b57"><b>uint16_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>uint32_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>uint64_t</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>float</b></font> number);
                variablebuffer  *write(<font color="#2e8b57"><b>double</b></font> number);
                        <font color="#0000ff">// Writes &quot;data&quot; 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="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *data, <font color="#2e8b57"><b>size_t</b></font> size);
                variablebuffer  *append(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string);
                variablebuffer  *append(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *string, <font color="#2e8b57"><b>size_t</b></font> size);
                variablebuffer  *append(<font color="#2e8b57"><b>char</b></font> character);
                variablebuffer  *append(<font color="#2e8b57"><b>int16_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>int32_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>int64_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> character);
                variablebuffer  *append(<font color="#2e8b57"><b>uint16_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>uint32_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>uint64_t</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>float</b></font> number);
                variablebuffer  *append(<font color="#2e8b57"><b>double</b></font> number);
                        <font color="#0000ff">// Appends &quot;data&quot; to the variablebuffer.  The buffer</font>
                        <font color="#0000ff">// will grow to accommodate the new data.</font>

                <font color="#2e8b57"><b>ssize_t</b></font>       read(<font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *data, <font color="#2e8b57"><b>size_t</b></font> size);
                        <font color="#0000ff">// Reads &quot;size&quot; bytes from the variablebuffer at the</font>
                        <font color="#0000ff">// current position into &quot;data&quot;.  Also increments the</font>
                        <font color="#0000ff">// current position by &quot;size&quot; bytes.</font>

                <font color="#2e8b57"><b>void</b></font>  clear();
                        <font color="#0000ff">// Empties the variablebuffer.</font>

                <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font>   *getBuffer();
                                <font color="#0000ff">// Returns the current data stored in the</font>
                                <font color="#0000ff">// variablebuffer.</font>
                <font color="#2e8b57"><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="#2e8b57"><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="#2e8b57"><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="#2e8b57"><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="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> *detachBuffer();
                                <font color="#0000ff">// Returns a pointer to the buffer currently</font>
                                <font color="#0000ff">// stored in the variablebuffer, then resets</font>
                                <font color="#0000ff">// the variablebuffer such that it will no</font>
                                <font color="#0000ff">// longer use that buffer.</font>
                                <font color="#0000ff">//</font>
                                <font color="#0000ff">// The calling program must deallocate the</font>
                                <font color="#0000ff">// buffer returned from this method.</font>

<font color="#a020f0">        #include </font><font color="#ff00ff">&lt;rudiments/private/variablebuffer.h&gt;</font>
};

<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>

<font color="#a020f0">#endif</font>
</pre>
</body>
</html>