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 
21 template <>
22 class WvBufBase<unsigned char> :
23  public WvBufBaseCommonImpl<unsigned char>
24 {
25 public:
26  explicit WvBufBase(WvBufStore *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 
151 private:
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 
164 class WvInPlaceBuf : public WvInPlaceBufBase<unsigned char>
165 {
166 public:
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 
187 class WvConstInPlaceBuf : public WvConstInPlaceBufBase<unsigned char>
188 {
189 public:
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 
206 class WvCircularBuf : public WvCircularBufBase<unsigned char>
207 {
208 public:
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 
227 
230 
233 
236 
239 
242 {
243  WvString xstr;
244 
245 public:
251  explicit WvConstStringBuffer(WvStringParm _str);
252 
255 
261  void reset(WvStringParm _str);
262 
269  { return xstr; }
270 };
271 
272 #endif // __WVBUFFER_H
WvBufBaseCommonImpl::poke
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
WvBufBase
The generic buffer base type.
Definition: wvbufbase.h:15
WvBufBase< unsigned char >::putch
void putch(int ch)
Puts a single character into the buffer as an int.
Definition: wvbuf.h:76
WvConstStringBuffer::str
WvString str()
Returns the string that backs the array.
Definition: wvbuf.h:268
WvBufBaseCommonImpl::move
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
WvConstStringBuffer
A raw memory read-only buffer backed by a constant WvString.
Definition: wvbuf.h:241
WvBufBase< unsigned char >::getch
int getch()
Returns a single character from the buffer as an int.
Definition: wvbuf.h:66
WvConstInPlaceBufBase
A buffer that wraps a pre-allocated array and provides read-only access to its elements.
Definition: wvbufbase.h:727
WvBufViewBase
A buffer that provides a read-write view over another buffer with a different datatype.
Definition: wvbufbase.h:1052
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvInPlaceBufBase
A buffer that wraps a pre-allocated array and provides read-write access to its elements.
Definition: wvbufbase.h:603
WvConstInPlaceBufBase::reset
void reset(const T *_data, size_t _avail)
Resets the underlying buffer pointer and properties.
Definition: wvbufbase.h:777
get
Interface * get(IObject *aObj)
XPLC equivalent to dynamic_cast.
Definition: utils.h:184
WvCircularBufBase
A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circ...
Definition: wvbufbase.h:813
WvInPlaceBuf
The in place raw memory buffer type.
Definition: wvbuf.h:164
WvCircularBufBase::reset
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
Definition: wvbufbase.h:910
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvBufBase< unsigned char >::peekch
int peekch(int offset=0)
Peeks a single character from the buffer as an int.
Definition: wvbuf.h:87
WvBufBaseCommonImpl::put
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
WvBufStore
The abstract buffer storage base class.
Definition: wvbufstore.h:26
WvBufBase< unsigned char >::notmatch
size_t notmatch(const void *bytelist, size_t numbytes)
Returns the number of leading buffer elements that do not match any of those in the list.
Definition: wvbuf.h:125
WvConstInPlaceBuf
The const in place raw memory buffer type.
Definition: wvbuf.h:187
WvConstStringBuffer::WvConstStringBuffer
WvConstStringBuffer()
Creates a new empty buffer backed by a null string.
Definition: wvbuffer.cc:106
WvInPlaceBufBase::reset
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
Definition: wvbufbase.h:698
WvNullBufBase
A buffer that is always empty.
Definition: wvbufbase.h:989
WvBufCursorBase
A buffer that acts like a cursor over a portion of another buffer.
Definition: wvbufbase.h:1014
WvDynBufBase< unsigned char >
WvCircularBuf
The circular in place raw memory buffer type.
Definition: wvbuf.h:206
WvBufBase< unsigned char >::match
size_t match(const char *chlist)
Returns the number of leading buffer elements that match any of those in the list.
Definition: wvbuf.h:115
WvBufBaseCommonImpl
An abstract generic buffer template.
Definition: wvbufbase.h:36
WvBufBase< unsigned char >::match
size_t match(const void *bytelist, size_t numbytes)
Returns the number of leading buffer elements that match any of those in the list.
Definition: wvbuf.h:106
WvConstStringBuffer::reset
void reset(WvStringParm _str)
Resets the buffer contents to a new string.
Definition: wvbuffer.cc:111
WvBufBase< unsigned char >::notmatch
size_t notmatch(const char *chlist)
Returns the number of leading buffer elements that do not match any of those in the list.
Definition: wvbuf.h:134