plptools
Loading...
Searching...
No Matches
bufferstore.h
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) 1999-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#ifndef _BUFFERSTORE_H_
22#define _BUFFERSTORE_H_
23
24#include "config.h"
25
26#include <iostream>
27#include <cstdint>
28
29#include <sys/types.h>
30
38public:
43
51 bufferStore(const unsigned char *buf, long len);
52
57
65 bufferStore(const bufferStore &b);
66
71
77 unsigned long getLen() const;
78
86 unsigned char getByte(long pos = 0) const;
87
95 uint16_t getWord(long pos = 0) const;
96
104 uint32_t getDWord(long pos = 0) const;
105
113 int32_t getSDWord(long pos = 0) const;
114
122 const char * getString(long pos = 0) const;
123
129 void discardFirstBytes(int len = 0);
130
139 friend std::ostream &operator<<(std::ostream &s, const bufferStore &m);
140
146 bool empty() const;
147
154 void init();
155
163 void init(const unsigned char * buf, long len);
164
170 void addByte(unsigned char c);
171
177 void addWord(int w);
178
184 void addDWord(long dw);
185
194 void addString(const char *s);
195
204 void addStringT(const char *s);
205
212 void addBytes(const unsigned char *buf, int len);
213
223 void addBuff(const bufferStore &b, long maxLen = -1);
224
231 void truncate(long newLen);
232
238 void prependByte(unsigned char c);
239
245 void prependWord(int w);
246
247private:
248 void checkAllocd(long newLen);
249
250 long len;
252 long start;
253 unsigned char * buff;
254
255 enum c { MIN_LEN = 300 };
256};
257
258inline bool bufferStore::empty() const {
259 return (len - start) == 0;
260}
261
262#endif
A generic container for an array of bytes.
Definition: bufferstore.h:37
void discardFirstBytes(int len=0)
Removes bytes from the start of the buffer.
Definition: bufferstore.cc:143
void init()
Initializes the bufferStore.
Definition: bufferstore.cc:77
uint16_t getWord(long pos=0) const
Retrieves the word at index pos.
Definition: bufferstore.cc:102
void addBuff(const bufferStore &b, long maxLen=-1)
Appends data to the content of this instance.
Definition: bufferstore.cc:182
void checkAllocd(long newLen)
Definition: bufferstore.cc:148
bufferStore()
Constructs a new bufferStore.
Definition: bufferstore.cc:39
void addByte(unsigned char c)
Appends a byte to the content of this instance.
Definition: bufferstore.cc:159
void addBytes(const unsigned char *buf, int len)
Appends data to the content of this instance.
Definition: bufferstore.cc:176
const char * getString(long pos=0) const
Retrieves the characters at index pos.
Definition: bufferstore.cc:120
void prependByte(unsigned char c)
Prepends a byte to the content of this instance.
Definition: bufferstore.cc:212
unsigned char * buff
Definition: bufferstore.h:253
void prependWord(int w)
Prepends a word to the content of this instance.
Definition: bufferstore.cc:218
long lenAllocd
Definition: bufferstore.h:251
bufferStore & operator=(const bufferStore &)
Copies a bufferStore.
Definition: bufferstore.cc:67
bool empty() const
Tests if the bufferStore is empty.
Definition: bufferstore.h:258
void addDWord(long dw)
Appends a dword to the content of this instance.
Definition: bufferstore.cc:199
void addStringT(const char *s)
Appends a string to the content of this instance.
Definition: bufferstore.cc:171
void truncate(long newLen)
Truncates the buffer.
Definition: bufferstore.cc:207
void addWord(int w)
Appends a word to the content of this instance.
Definition: bufferstore.cc:193
unsigned long getLen() const
Retrieves the length of a bufferStore.
Definition: bufferstore.cc:94
~bufferStore()
Destroys a bufferStore instance.
Definition: bufferstore.cc:89
void addString(const char *s)
Appends a string to the content of this instance.
Definition: bufferstore.cc:164
uint32_t getDWord(long pos=0) const
Retrieves the dword at index pos.
Definition: bufferstore.cc:106
unsigned char getByte(long pos=0) const
Retrieves the byte at index pos.
Definition: bufferstore.cc:98
int32_t getSDWord(long pos=0) const
Retrieves the signed dword at index pos.
Definition: bufferstore.cc:113
friend std::ostream & operator<<(std::ostream &s, const bufferStore &m)
Prints a dump of the content.
Definition: bufferstore.cc:124