WvStreams
wvbuf.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Specializations of the generic buffering API and a few new buffers.
6 */
7#ifndef __WVBUFFER_H
8#define __WVBUFFER_H
9
10#include "wvstring.h"
11#include "wvbufbase.h"
12
13/***** Specialization for 'unsigned char' buffers *****/
14
21template <>
22class WvBufBase<unsigned char> :
23 public WvBufBaseCommonImpl<unsigned char>
24{
25public:
26 explicit WvBufBase(WvBufStore *store) :
27 WvBufBaseCommonImpl<unsigned char>(store) { }
28
33 void putstr(WvStringParm str);
34 void putstr(WVSTRING_FORMAT_DECL)
35 { putstr(WvString(WVSTRING_FORMAT_CALL)); }
36
47 WvString getstr();
48
55 WvString getstr(size_t len);
56
57 /*** Get/put characters as integer values ***/
58
66 int getch()
67 { return int(get()); }
68
76 void putch(int ch)
77 { put((unsigned char)ch); }
78
87 int peekch(int offset = 0)
88 { return int(peek(offset)); }
89
97 size_t strchr(int ch);
98
106 size_t match(const void *bytelist, size_t numbytes)
107 { return _match(bytelist, numbytes, false); }
108
115 size_t match(const char *chlist)
116 { return match(chlist, strlen(chlist)); }
117
125 size_t notmatch(const void *bytelist, size_t numbytes)
126 { return _match(bytelist, numbytes, true); }
127
134 size_t notmatch(const char *chlist)
135 { return notmatch(chlist, strlen(chlist)); }
136
137 /*** Overload put() and move() to accept void pointers ***/
138
139 void put(unsigned char value)
141 void put(const void *data, size_t count)
143 (const unsigned char*)data, count); }
144 void move(void *data, size_t count)
146 (unsigned char*)data, count); }
147 void poke(void *data, int offset, size_t count)
149 (unsigned char*)data, offset, count); }
150
151private:
152 // moved here to avoid ambiguities between the match variants
153 size_t _match(const void *bytelist, size_t numbytes, bool reverse);
154};
155
156
157
158/***** Declarations for some commonly used memory buffers *****/
159
164class WvInPlaceBuf : public WvInPlaceBufBase<unsigned char>
165{
166public:
167 WvInPlaceBuf(void *_data, size_t _avail, size_t _size,
168 bool _autofree = false) :
169 WvInPlaceBufBase<unsigned char>((unsigned char*)_data,
170 _avail, _size, _autofree) { }
171 explicit WvInPlaceBuf(size_t _size) :
173 WvInPlaceBuf() :
175 void reset(void *_data, size_t _avail, size_t _size,
176 bool _autofree = false)
177 {
179 (unsigned char*)_data, _avail, _size, _autofree);
180 }
181};
182
187class WvConstInPlaceBuf : public WvConstInPlaceBufBase<unsigned char>
188{
189public:
190 WvConstInPlaceBuf(const void *_data, size_t _avail) :
192 (const unsigned char*)_data, _avail) { }
195 void reset(const void *_data, size_t _avail)
196 {
198 (const unsigned char*)_data, _avail);
199 }
200};
201
206class WvCircularBuf : public WvCircularBufBase<unsigned char>
207{
208public:
209 WvCircularBuf(void *_data, size_t _avail, size_t _size,
210 bool _autofree = false) :
211 WvCircularBufBase<unsigned char>((unsigned char*)_data,
212 _avail, _size, _autofree) { }
213 explicit WvCircularBuf(size_t _size) :
215 WvCircularBuf() :
217 void reset(void *_data, size_t _avail, size_t _size,
218 bool _autofree = false)
219 {
221 (unsigned char*)_data, _avail, _size, _autofree);
222 }
223};
224
226typedef WvBufBase<unsigned char> WvBuf;
227
230
233
236
239
242{
243 WvString xstr;
244
245public:
251 explicit WvConstStringBuffer(WvStringParm _str);
252
255
261 void reset(WvStringParm _str);
262
269 { return xstr; }
270};
271
272#endif // __WVBUFFER_H
An abstract generic buffer template.
Definition wvbufbase.h:37
void poke(const T *data, int offset, size_t count)
Efficiently copies the specified number of elements from the specified storage location into the buff...
Definition wvbufbase.h:504
void put(const T *data, size_t count)
Writes the specified number of elements from the specified storage location into the buffer at its ta...
Definition wvbufbase.h:483
const T * peek(int offset, size_t count)
Returns a const pointer into the buffer at the specified offset to the specified number of elements w...
Definition wvbufbase.h:225
T get()
Reads the next element from the buffer.
Definition wvbufbase.h:272
void move(T *buf, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
Definition wvbufbase.h:309
The generic buffer base type.
Definition wvbufbase.h:587
A buffer that acts like a cursor over a portion of another buffer.
Definition wvbufbase.h:1015
The abstract buffer storage base class.
Definition wvbufstore.h:27
A buffer that provides a read-write view over another buffer with a different datatype.
Definition wvbufbase.h:1053
A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circ...
Definition wvbufbase.h:814
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
Definition wvbufbase.h:910
The circular in place raw memory buffer type.
Definition wvbuf.h:207
A buffer that wraps a pre-allocated array and provides read-only access to its elements.
Definition wvbufbase.h:728
void reset(const T *_data, size_t _avail)
Resets the underlying buffer pointer and properties.
Definition wvbufbase.h:777
The const in place raw memory buffer type.
Definition wvbuf.h:188
A raw memory read-only buffer backed by a constant WvString.
Definition wvbuf.h:242
WvConstStringBuffer()
Creates a new empty buffer backed by a null string.
Definition wvbuffer.cc:106
void reset(WvStringParm _str)
Resets the buffer contents to a new string.
Definition wvbuffer.cc:111
WvString str()
Returns the string that backs the array.
Definition wvbuf.h:268
A buffer that dynamically grows and shrinks based on demand.
Definition wvbufbase.h:954
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
A buffer that wraps a pre-allocated array and provides read-write access to its elements.
Definition wvbufbase.h:604
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
Definition wvbufbase.h:698
The in place raw memory buffer type.
Definition wvbuf.h:165
A buffer that is always empty.
Definition wvbufbase.h:990
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330