File: rawbuffer.h.html

package info (click to toggle)
rudiments 0.31-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,516 kB
  • ctags: 3,248
  • sloc: asm: 23,776; cpp: 22,792; sh: 7,769; ansic: 1,769; makefile: 1,054; xml: 169; perl: 19
file content (150 lines) | stat: -rw-r--r-- 14,873 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/rawbuffer.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) 2004 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>

<font color="#a020f0">#ifndef RUDIMENTS_RAWBUFFER_H</font>
<font color="#a020f0">#define RUDIMENTS_RAWBUFFER_H</font>

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

<font color="#0000ff">// The rawbuffer class provides methods for operating on raw memory buffers.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Unlike the functions in sys/string.h, these methods are NULL safe.  If any of</font>
<font color="#0000ff">// the pointer arguments are NULL, your application will not crash.</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> rawbuffer {
        <font color="#a52a2a"><b>public</b></font>:

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *duplicate(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *src, <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Allocates a buffer of &quot;size&quot; bytes,</font>
                                <font color="#0000ff">// copies &quot;size&quot; bytes of &quot;src&quot; into it</font>
                                <font color="#0000ff">// and returns the buffer.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *copy(<font color="#2e8b57"><b>void</b></font> *dest, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *src,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Copies &quot;size&quot; bytes from &quot;src&quot; into &quot;dest&quot;.</font>
                                <font color="#0000ff">// &quot;src&quot; and &quot;dest&quot; may NOT overlap.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *copyWithOverlap(<font color="#2e8b57"><b>void</b></font> *dest,
                                                        <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *src,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Copies &quot;size&quot; bytes from &quot;src&quot; to &quot;dest&quot;.</font>
                                <font color="#0000ff">// &quot;src&quot; and &quot;dest&quot; may overlap.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *copyUntil(<font color="#2e8b57"><b>void</b></font> *dest, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *src,
                                                        <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> character,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Copies bytes from &quot;src&quot; into &quot;dest&quot; until</font>
                                <font color="#0000ff">// &quot;character&quot; is encountered in &quot;src&quot; or &quot;size&quot;</font>
                                <font color="#0000ff">// bytes have been copied.</font>
                                <font color="#0000ff">// &quot;src&quot; and &quot;dest&quot; may NOT overlap.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *copySwapBytes(<font color="#2e8b57"><b>void</b></font> *dest,
                                                        <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *src,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Copies &quot;size&quot; bytes from &quot;src&quot; into &quot;dest&quot;</font>
                                <font color="#0000ff">// while swapping byte order.  Useful for</font>
                                <font color="#0000ff">// exchanging data between big and little</font>
                                <font color="#0000ff">// endian machines.</font>
                                <font color="#0000ff">// &quot;src&quot; and &quot;dest&quot; may NOT overlap.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *set(<font color="#2e8b57"><b>void</b></font> *dest, <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> character,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Sets &quot;size&quot; bytes of &quot;dest&quot; to &quot;character&quot;.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *zero(<font color="#2e8b57"><b>void</b></font> *dest, <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Sets &quot;size&quot; bytes of &quot;dest&quot; to NULL.</font>
                                <font color="#0000ff">// Returns a pointer to &quot;dest&quot;.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>int</b></font>    compare(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *s1, <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *s2,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Returns an integer less than, equal to or</font>
                                <font color="#0000ff">// greater than 0 if &quot;size&quot; bytes of &quot;s1&quot; are</font>
                                <font color="#0000ff">// less than, equal to or greater than &quot;size&quot;</font>
                                <font color="#0000ff">// bytes of &quot;s2&quot;.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *findFirst(<font color="#2e8b57"><b>void</b></font> *haystack,
                                                <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> needle,
                                                <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Returns a pointer to the first occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *findLast(<font color="#2e8b57"><b>void</b></font> *haystack,
                                                <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> needle,
                                                <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Returns a pointer to the last occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *findFirst(<font color="#2e8b57"><b>void</b></font> *haystack,
                                                <font color="#2e8b57"><b>size_t</b></font> haystacksize,
                                                <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *needle,
                                                <font color="#2e8b57"><b>size_t</b></font> needleize);
                                <font color="#0000ff">// Returns a pointer to the first occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>void</b></font>   *findLast(<font color="#2e8b57"><b>void</b></font> *haystack,
                                                <font color="#2e8b57"><b>size_t</b></font> haystacksize,
                                                <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *needle,
                                                <font color="#2e8b57"><b>size_t</b></font> needleize);
                                <font color="#0000ff">// Returns a pointer to the last occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font>     *findFirst(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *haystack,
                                                        <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> needle,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Returns a pointer to the first occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font>     *findLast(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *haystack,
                                                        <font color="#2e8b57"><b>unsigned</b></font> <font color="#2e8b57"><b>char</b></font> needle,
                                                        <font color="#2e8b57"><b>size_t</b></font> size);
                                <font color="#0000ff">// Returns a pointer to the last occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>

                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font>     *findFirst(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *haystack,
                                                        <font color="#2e8b57"><b>size_t</b></font> haystacksize,
                                                        <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *needle,
                                                        <font color="#2e8b57"><b>size_t</b></font> needleize);
                                <font color="#0000ff">// Returns a pointer to the first occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>
                <font color="#2e8b57"><b>static</b></font> <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font>     *findLast(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *haystack,
                                                        <font color="#2e8b57"><b>size_t</b></font> haystacksize,
                                                        <font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>void</b></font> *needle,
                                                        <font color="#2e8b57"><b>size_t</b></font> needleize);
                                <font color="#0000ff">// Returns a pointer to the last occurrance</font>
                                <font color="#0000ff">// of &quot;needle&quot; in the first &quot;size&quot; bytes of</font>
                                <font color="#0000ff">// &quot;haystack&quot;.</font>
                                <font color="#0000ff">// Returns NULL if no match is found.</font>
};

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

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