aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bufferarray.h
blob: 358d428dc47f7ec10285359c082272438099021c (plain)
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
#ifndef _bufferarray_h
#define _bufferarray_h

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
class bufferStore;

/**
 * An array of bufferStores
 */
class bufferArray {
public:
	/**
	 * constructs a new bufferArray.
	 * A minimum of @ref ALLOC_MIN
	 * elements is allocated.
	 */
	bufferArray();

	/**
	 * Constructs a new bufferArray.
	 *
	 * @param a The initial contents for this array.
	 */
	bufferArray(const bufferArray &a);

	/**
	 * Destroys the bufferArray.
	 */
	~bufferArray();

	/**
	 * Copys the bufferArray.
	 */
	bufferArray &operator =(const bufferArray &a);

	/**
	 * Checks if this bufferArray is empty.
	 *
	 * @return true if the bufferArray is empty.
	 */
	bool empty() const;

	/**
	 * Retrieves the bufferStore at given index.
	 *
	 * @return The bufferStore at index.
	 */
	bufferStore &operator [](const unsigned long index);

	/**
	 * Appends a bufferStore to a bufferArray.
	 *
	 * @param s The bufferStore to be appended.
	 *
	 * @returns A new bufferArray with bufferStore appended to.
	 */
	bufferArray operator +(const bufferStore &s);

	/**
	 * Concatenates two bufferArrays.
	 *
	 * @param a The bufferArray to be appended.
	 *
	 * @returns A new bufferArray consisting with a appended.
	 */
	bufferArray operator +(const bufferArray &a);

	/**
	 * Appends a bufferStore to current instance.
	 *
	 * @param s The bufferStore to append.
	 *
	 * @returns A reference to the current instance with s appended.
	 */
	bufferArray &operator +=(const bufferStore &s);

	/**
	 * Appends a bufferArray to current instance.
	 *
	 * @param a The bufferArray to append.
	 *
	 * @returns A reference to the current instance with a appended.
	 */
	bufferArray &operator +=(const bufferArray &a);

	/**
	 * Removes the first bufferStore.
	 *
	 * @return The removed bufferStore.
	 */
	bufferStore pop(void);

	/**
	 * Inserts a bufferStore at index 0.
	 *
	 * @param b The bufferStore to be inserted.
	 */
	void push(const bufferStore& b);

	/**
	 * Appends a bufferStore.
	 *
	 * @param b The bufferStore to be appended.
	 */
	void append(const bufferStore& b);

	/**
	 * Evaluates the current length.
	 *
	 * @return The current number of bufferStores
	 */
	long length(void);

	/**
	 * Empties the bufferArray.
	 */
	void clear(void);

private:
	/**
	 * Minimum number of bufferStores to
	 * allocate.
	 */
	static const long ALLOC_MIN = 5;

	/**
	 * The current number of bufferStores in
	 * this bufferArray.
	 */
	long len;

	/**
	 * The current number of bufferStores
	 * allocated.
	 */
	long lenAllocd;

	/**
	 * The content.
	 */
	bufferStore* buff;
};

inline bool bufferArray::empty() const { return len == 0; }

#endif