plptools
Loading...
Searching...
No Matches
bufferStore Class Reference

A generic container for an array of bytes. More...

#include <bufferstore.h>

Public Member Functions

 bufferStore ()
 Constructs a new bufferStore. More...
 
 bufferStore (const unsigned char *buf, long len)
 Constructs a new bufferStore and initializes its content. More...
 
 ~bufferStore ()
 Destroys a bufferStore instance. More...
 
 bufferStore (const bufferStore &b)
 Constructs a new bufferStore and initializes its content. More...
 
bufferStoreoperator= (const bufferStore &)
 Copies a bufferStore. More...
 
unsigned long getLen () const
 Retrieves the length of a bufferStore. More...
 
unsigned char getByte (long pos=0) const
 Retrieves the byte at index pos. More...
 
uint16_t getWord (long pos=0) const
 Retrieves the word at index pos. More...
 
uint32_t getDWord (long pos=0) const
 Retrieves the dword at index pos. More...
 
int32_t getSDWord (long pos=0) const
 Retrieves the signed dword at index pos. More...
 
const char * getString (long pos=0) const
 Retrieves the characters at index pos. More...
 
void discardFirstBytes (int len=0)
 Removes bytes from the start of the buffer. More...
 
bool empty () const
 Tests if the bufferStore is empty. More...
 
void init ()
 Initializes the bufferStore. More...
 
void init (const unsigned char *buf, long len)
 Initializes the bufferStore with a given data. More...
 
void addByte (unsigned char c)
 Appends a byte to the content of this instance. More...
 
void addWord (int w)
 Appends a word to the content of this instance. More...
 
void addDWord (long dw)
 Appends a dword to the content of this instance. More...
 
void addString (const char *s)
 Appends a string to the content of this instance. More...
 
void addStringT (const char *s)
 Appends a string to the content of this instance. More...
 
void addBytes (const unsigned char *buf, int len)
 Appends data to the content of this instance. More...
 
void addBuff (const bufferStore &b, long maxLen=-1)
 Appends data to the content of this instance. More...
 
void truncate (long newLen)
 Truncates the buffer. More...
 
void prependByte (unsigned char c)
 Prepends a byte to the content of this instance. More...
 
void prependWord (int w)
 Prepends a word to the content of this instance. More...
 

Private Types

enum  c { MIN_LEN = 300 }
 

Private Member Functions

void checkAllocd (long newLen)
 

Private Attributes

long len
 
long lenAllocd
 
long start
 
unsigned char * buff
 

Friends

std::ostreamoperator<< (std::ostream &s, const bufferStore &m)
 Prints a dump of the content. More...
 

Detailed Description

A generic container for an array of bytes.

bufferStore provides an array of bytes which can be accessed using various types.

Definition at line 37 of file bufferstore.h.

Member Enumeration Documentation

◆ c

enum bufferStore::c
private
Enumerator
MIN_LEN 

Definition at line 255 of file bufferstore.h.

Constructor & Destructor Documentation

◆ bufferStore() [1/3]

bufferStore::bufferStore ( )

Constructs a new bufferStore.

Definition at line 39 of file bufferstore.cc.

◆ bufferStore() [2/3]

bufferStore::bufferStore ( const unsigned char *  buf,
long  len 
)

Constructs a new bufferStore and initializes its content.

Parameters
bufPointer to data for initialization.
lenLength of data for initialization.

Definition at line 57 of file bufferstore.cc.

◆ ~bufferStore()

bufferStore::~bufferStore ( )

Destroys a bufferStore instance.

Definition at line 89 of file bufferstore.cc.

◆ bufferStore() [3/3]

bufferStore::bufferStore ( const bufferStore b)

Constructs a new bufferStore and initializes its content.

Parameters
bA bufferStore, whose content is used for initialization.

Definition at line 47 of file bufferstore.cc.

Member Function Documentation

◆ addBuff()

void bufferStore::addBuff ( const bufferStore b,
long  maxLen = -1 
)

Appends data to the content of this instance.

Parameters
bThe bufferStore whose content to append.
maxLenLength of content to append. If maxLen is less than 0 or greater than the current length of b , then the whole content of b is appended.

Definition at line 182 of file bufferstore.cc.

◆ addByte()

void bufferStore::addByte ( unsigned char  c)

Appends a byte to the content of this instance.

Parameters
cThe byte to append.

Definition at line 159 of file bufferstore.cc.

◆ addBytes()

void bufferStore::addBytes ( const unsigned char *  buf,
int  len 
)

Appends data to the content of this instance.

Parameters
bufThe data to append.
lenLength of data.

Definition at line 176 of file bufferstore.cc.

◆ addDWord()

void bufferStore::addDWord ( long  dw)

Appends a dword to the content of this instance.

Parameters
dwThe dword to append.

Definition at line 199 of file bufferstore.cc.

◆ addString()

void bufferStore::addString ( const char *  s)

Appends a string to the content of this instance.

The trailing zero byte is not copied to the content.

Parameters
sThe string to append.

Definition at line 164 of file bufferstore.cc.

◆ addStringT()

void bufferStore::addStringT ( const char *  s)

Appends a string to the content of this instance.

The trailing zero byte is copied to the content.

Parameters
sThe string to append.

Definition at line 171 of file bufferstore.cc.

◆ addWord()

void bufferStore::addWord ( int  w)

Appends a word to the content of this instance.

Parameters
wThe word to append.

Definition at line 193 of file bufferstore.cc.

◆ checkAllocd()

void bufferStore::checkAllocd ( long  newLen)
private

Definition at line 148 of file bufferstore.cc.

◆ discardFirstBytes()

void bufferStore::discardFirstBytes ( int  len = 0)

Removes bytes from the start of the buffer.

Parameters
lenNumber of bytes to remove.

Definition at line 143 of file bufferstore.cc.

◆ empty()

bool bufferStore::empty ( ) const
inline

Tests if the bufferStore is empty.

Returns
true, if the bufferStore is empty; false, if it contains data.

Definition at line 258 of file bufferstore.h.

◆ getByte()

unsigned char bufferStore::getByte ( long  pos = 0) const

Retrieves the byte at index pos.

Parameters
posThe index of the byte to retrieve.
Returns
The value of the byte at index pos

Definition at line 98 of file bufferstore.cc.

◆ getDWord()

uint32_t bufferStore::getDWord ( long  pos = 0) const

Retrieves the dword at index pos.

Parameters
posThe index of the dword to retrieve.
Returns
The value of the dword at index pos

Definition at line 106 of file bufferstore.cc.

◆ getLen()

unsigned long bufferStore::getLen ( ) const

Retrieves the length of a bufferStore.

Returns
The current length of the contents in bytes.

Definition at line 94 of file bufferstore.cc.

◆ getSDWord()

int32_t bufferStore::getSDWord ( long  pos = 0) const

Retrieves the signed dword at index pos.

Parameters
posThe index of the signed dword to retrieve.
Returns
The value of the signed dword at index pos

Definition at line 113 of file bufferstore.cc.

◆ getString()

const char * bufferStore::getString ( long  pos = 0) const

Retrieves the characters at index pos.

Parameters
posThe index of the characters to retrieve.
Returns
A pointer to characters at index pos

Definition at line 120 of file bufferstore.cc.

◆ getWord()

uint16_t bufferStore::getWord ( long  pos = 0) const

Retrieves the word at index pos.

Parameters
posThe index of the word to retrieve.
Returns
The value of the word at index pos

Definition at line 102 of file bufferstore.cc.

◆ init() [1/2]

void bufferStore::init ( )

Initializes the bufferStore.

All data is removed, the length is reset to 0.

Definition at line 77 of file bufferstore.cc.

◆ init() [2/2]

void bufferStore::init ( const unsigned char *  buf,
long  len 
)

Initializes the bufferStore with a given data.

Parameters
bufPointer to data to initialize from.
lenLength of data.

Definition at line 82 of file bufferstore.cc.

◆ operator=()

bufferStore & bufferStore::operator= ( const bufferStore a)

Copies a bufferStore.

Definition at line 67 of file bufferstore.cc.

◆ prependByte()

void bufferStore::prependByte ( unsigned char  c)

Prepends a byte to the content of this instance.

Parameters
cThe byte to append.

Definition at line 212 of file bufferstore.cc.

◆ prependWord()

void bufferStore::prependWord ( int  w)

Prepends a word to the content of this instance.

Parameters
wThe word to append.

Definition at line 218 of file bufferstore.cc.

◆ truncate()

void bufferStore::truncate ( long  newLen)

Truncates the buffer.

If the buffer is smaller, does nothing.

Parameters
newLenThe new length of the buffer.

Definition at line 207 of file bufferstore.cc.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream s,
const bufferStore m 
)
friend

Prints a dump of the content.

Parameters
sThe stream to write to.
mThe bufferStore do be dumped.
Returns
The stream.

Definition at line 124 of file bufferstore.cc.

Member Data Documentation

◆ buff

unsigned char* bufferStore::buff
private

Definition at line 253 of file bufferstore.h.

◆ len

long bufferStore::len
private

Definition at line 250 of file bufferstore.h.

◆ lenAllocd

long bufferStore::lenAllocd
private

Definition at line 251 of file bufferstore.h.

◆ start

long bufferStore::start
private

Definition at line 252 of file bufferstore.h.


The documentation for this class was generated from the following files: