File: variablebuffer.h

package info (click to toggle)
librudiments0 0.27-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,528 kB
  • ctags: 2,284
  • sloc: cpp: 14,657; sh: 7,547; ansic: 2,664; makefile: 945; xml: 15
file content (71 lines) | stat: -rw-r--r-- 2,512 bytes parent folder | download
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
// Copyright (c) 2002 David Muse
// See the COPYING file for more information.

#ifndef RUDIMENTS_VARIABLEBUFFER_H
#define RUDIMENTS_VARIABLEBUFFER_H

#include <rudiments/private/variablebufferincludes.h>

// The variablebuffer class can be used to store raw data of arbitrary length.

class variablebuffer {
	public:
			variablebuffer(size_t initialsize, size_t increment);
			variablebuffer(unsigned char *initialcontents,
					size_t initialsize, size_t increment);
			// Creates a new buffer of size "initialsize"
			// which will grow in chunks of size "increment".
			// The position at which the first write or append
			// will occur is initialized to 0.
		virtual	~variablebuffer();

		void	setPosition(size_t pos);
			// Sets the position at which the next read or write
			// will occur to "pos".  If the position is set beyond
			// the end of the buffer, the buffer will grow but the
			// data between the current end of the buffer and the
			// new position will be undefined.

		// The write() and append() methods return a pointer to the
		// variablebuffer instance.  This enables chaining:
		//
		//	sb->write(data1)->write(data2)->write(data3);
		//	 	or
		//	sb->append(data1)->append(data2)->append(data3);
		variablebuffer	*write(const unsigned char *data, size_t size);
			// Writes "data" to the variablebuffer at the current
			// position.  If necessary, the buffer will grow to
			// accommodate the new data.
		variablebuffer	*append(const unsigned char *data, size_t size);
			// Appends "data" to the variablebuffer.  The buffer
			// will grow to accommodate the new data.

		ssize_t	read(unsigned char *data, size_t size);
			// Reads "size" bytes from the variablebuffer at the
			// current position into "data".  Also increments the
			// current position by "size" bytes.

		void	clear();
			// Empties the variablebuffer.

		unsigned char	*getBuffer();
				// Returns the current data stored in the
				// variablebuffer.
		size_t		getSize();
				// Returns the current amount of data stored
				// in the variablebuffer.
		size_t		getPosition();
				// Returns the position in the buffer at which
				// the next write will occur.
		size_t		getEnd();
				// Returns the position in the buffer at which
				// the next append will occur.
		size_t		getActualSize();
				// Returns the actual size of the buffer which
				// may be larger than the value returned by
				// getSize() since the buffer grows in chunks.

	#include <rudiments/private/variablebuffer.h>
};

#endif