plptools
Loading...
Searching...
No Matches
bufferarray.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 2000, 2001 Fritz Elfert <felfert@to.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#include "config.h"
22
23#include "bufferstore.h"
24#include "bufferarray.h"
25
27{
28 len = 0;
31}
32
34{
35 len = a.len;
36 lenAllocd = a.lenAllocd;
38 for (int i = 0; i < len; i++)
39 buff[i] = a.buff[i];
40}
41
43{
44 delete []buff;
45}
46
48pop()
49{
50 bufferStore ret;
51 if (len > 0) {
52 ret = buff[0];
53 len--;
54 for (long i = 0; i < len; i++) {
55 buff[i] = buff[i + 1];
56 }
57 }
58 return ret;
59}
60
62append(const bufferStore & b)
63{
64 if (len == lenAllocd) {
67 for (long i = 0; i < len; i++) {
68 nb[i] = buff[i];
69 }
70 delete []buff;
71 buff = nb;
72 }
73 buff[len++] = b;
74}
75
77push(const bufferStore & b)
78{
79 if (len == lenAllocd)
82 for (long i = len; i > 0; i--) {
83 nb[i] = buff[i - 1];
84 }
85 nb[0] = b;
86 delete[]buff;
87 buff = nb;
88 len++;
89}
90
92length(void)
93{
94 return len;
95}
96
98clear(void)
99{
100 len = 0;
102 delete []buff;
104}
105
107operator =(const bufferArray & a)
108{
109 delete []buff;
110 len = a.len;
111 lenAllocd = a.lenAllocd;
113 for (int i = 0; i < len; i++)
114 buff[i] = a.buff[i];
115 return *this;
116}
117
119operator [](const unsigned long index)
120{
121 return buff[index];
122}
123
125operator +(const bufferStore &s)
126{
127 bufferArray res = *this;
128 res += s;
129 return res;
130}
131
134{
135 bufferArray res = *this;
136 res += a;
137 return res;
138}
139
142{
143 lenAllocd += a.lenAllocd;
145 for (int i = 0; i < len; i++)
146 nb[len + i] = buff[i];
147 for (int i = 0; i < a.len; i++)
148 nb[len + i] = a.buff[i];
149 len += a.len;
150 delete []buff;
151 buff = nb;
152 return *this;
153}
154
156operator +=(const bufferStore &s)
157{
158 append(s);
159 return *this;
160}
An array of bufferStores.
Definition: bufferarray.h:31
void push(const bufferStore &b)
Inserts a bufferStore at index 0.
Definition: bufferarray.cc:77
bufferStore pop(void)
Removes the first bufferStore.
Definition: bufferarray.cc:48
~bufferArray()
Destroys the bufferArray.
Definition: bufferarray.cc:42
long lenAllocd
The current number of bufferStores allocated.
Definition: bufferarray.h:157
long length(void)
Evaluates the current length.
Definition: bufferarray.cc:92
bufferArray operator+(const bufferStore &s)
Appends a bufferStore to a bufferArray.
Definition: bufferarray.cc:125
bufferStore & operator[](const unsigned long index)
Retrieves the bufferStore at given index.
Definition: bufferarray.cc:119
void clear(void)
Empties the bufferArray.
Definition: bufferarray.cc:98
bufferArray()
constructs a new bufferArray.
Definition: bufferarray.cc:26
static const long ALLOC_MIN
Minimum number of bufferStores to allocate.
Definition: bufferarray.h:145
bufferArray & operator=(const bufferArray &a)
Copys the bufferArray.
Definition: bufferarray.cc:107
void append(const bufferStore &b)
Appends a bufferStore.
Definition: bufferarray.cc:62
bufferStore * buff
The content.
Definition: bufferarray.h:162
bufferArray & operator+=(const bufferStore &s)
Appends a bufferStore to current instance.
Definition: bufferarray.cc:156
long len
The current number of bufferStores in this bufferArray.
Definition: bufferarray.h:151
A generic container for an array of bytes.
Definition: bufferstore.h:37
static rfsv * a
Definition: main.cc:53