libbbb  1.2.1
Groups common code used in some applications and libraries.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
bbb::ByteBuffer Class Reference

Represents a buffer capable of accumulating various kinds of values. More...

#include <bytebuffer.h>

Public Member Functions

 ByteBuffer (void)
 constructor;
 
 ~ByteBuffer (void)
 destructor;
 
bool isValid (void) const
 tell if the instance is valid or not
 
bool isEmpty (void) const
 tell if there is any data in this buffer
 
unsigned allocated (void) const
 number of allocated bytes in this buffer
 
unsigned size (void) const
 number of used bytes; lenght of the content
 
unsigned count (void) const
 number of used bytes; lenght of the content
 
unsigned lenght (void) const
 number of used bytes; lenght of the content
 
void seek (quint64 loc)
 resets the iterator to requested location
 
quint64 position (void) const
 get the position of the iterator
 
void reset (void)
 resets the buffer as if it was just allocated
 
bool reinitFromFile (QFile &file)
 resets the buffer to the content of the file
 
bool saveToFile (QFile &file)
 writes the content of the buffer to file
 
unsigned getRaw (unsigned bytes)
 reserves and updates used count
 
Methods used to "fill" a buffer
void append (int new_val)
 adds an integer value;
 
void append (unsigned new_val)
 adds an unsigned value;
 
void append (quint64 new_val)
 adds an integer value;
 
void append (qint64 new_val)
 adds an integer value;
 
void append (bool new_val)
 adds a boolean value;
 
void append (double new_val)
 adds a double value;
 
void append (const QString &new_val)
 adds a string value;
 
void append (const char *new_val, int len=-1, bool uncounted=false)
 adds a byte array;
 
Methods used to read a buffer
bool getValue (bool &out_val, quint64 offset)
 reads a boolean value; return false for errors More...
 
quint64 getValue (char *out_val, int max_buf, quint64 offset)
 reads a counted array of bytes in a user provided buffer More...
 
bool getValue (quint64 offset, int count, char *out_val)
 reads an uncounted array of characters More...
 
bool getValue (char **out_val, quint64 offset)
 reads a counted array of bytes in an internally provided buffer More...
 
bool getValue (double &out_val, quint64 offset)
 reads a double value More...
 
bool getValue (int &out_val, quint64 offset)
 reads a signed value More...
 
bool getValue (qint64 &out_val, quint64 offset)
 reads a signed value More...
 
bool getValue (QString &out_val, quint64 offset)
 reads a string value More...
 
bool getValue (quint64 &out_val, quint64 offset)
 reads an unsigned value More...
 
bool getValue (unsigned &out_val, quint64 offset)
 reads an unsigned value More...
 
Methods used to sequentially read a buffer
bool getValue (int &out_val)
 reads a signed value More...
 
bool getValue (unsigned &out_val)
 reads an unsigned value More...
 
bool getValue (qint64 &out_val)
 reads a signed value More...
 
bool getValue (quint64 &out_val)
 reads an unsigned value More...
 
bool getValue (bool &out_val)
 reads a boolean value More...
 
bool getValue (double &out_val)
 reads a real value More...
 
bool getValue (QString &out_val)
 reads a string value More...
 
bool getValue (char **out_val)
 reads a counted array of bytes in an internally provided buffer More...
 
quint64 getValue (char *out_val, int max_buf)
 reads a counted array of bytes in a user provided buffer More...
 
bool getValue (int count, char *out_buf)
 reads an uncounted array of characters More...
 
bool readUncountedBytes (int count, char *out_buf)
 reads an uncounted array of characters More...
 

Detailed Description

Represents a buffer capable of accumulating various kinds of values.

Member Function Documentation

bool ByteBuffer::getValue ( bool &  out_val,
quint64  offset 
)

reads a boolean value; return false for errors

Returns
true if all ok, false if out of buffer's bounds
quint64 ByteBuffer::getValue ( char *  out_val,
int  max_buf,
quint64  offset 
)

reads a counted array of bytes in a user provided buffer

The user must provide a valid pointer and correct buffer size.

The buffer should contain the size of the array and the array itself.

Returns
the number of bytes that were copied intro the buffer
bool ByteBuffer::getValue ( quint64  offset,
int  count,
char *  out_val 
)

reads an uncounted array of characters

Usable for fixed-lenght entries. The buffer is not expected to contain a counter. Used with signature bytes.

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( char **  out_val,
quint64  offset 
)

reads a counted array of bytes in an internally provided buffer

The user will have the ovnership of the returned buffer.

The buffer should contain the size of the array and the array itself.

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( double &  out_val,
quint64  offset 
)

reads a double value

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( int &  out_val,
quint64  offset 
)

reads a signed value

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( qint64 &  out_val,
quint64  offset 
)

reads a signed value

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( QString &  out_val,
quint64  offset 
)

reads a string value

The entry is expected to be counted.

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( quint64 &  out_val,
quint64  offset 
)

reads an unsigned value

Returns
true if all ok, false if out of buffer's bounds
bool ByteBuffer::getValue ( unsigned &  out_val,
quint64  offset 
)

reads an unsigned value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( int &  out_val)
inline

reads a signed value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( unsigned &  out_val)
inline

reads an unsigned value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( qint64 &  out_val)
inline

reads a signed value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( quint64 &  out_val)
inline

reads an unsigned value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( bool &  out_val)
inline

reads a boolean value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( double &  out_val)
inline

reads a real value

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( QString &  out_val)
inline

reads a string value

The entry is expected to be counted.

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::getValue ( char **  out_val)
inline

reads a counted array of bytes in an internally provided buffer

The user will have the ovnership of the returned buffer.

The buffer should contain the size of the array and the array itself.

Returns
true if all ok, false if out of buffer's bounds
quint64 bbb::ByteBuffer::getValue ( char *  out_val,
int  max_buf 
)
inline

reads a counted array of bytes in a user provided buffer

The user must provide a valid pointer and correct buffer size.

The buffer should contain the size of the array and the array itself.

Returns
the number of bytes that were copied intro the buffer
bool bbb::ByteBuffer::getValue ( int  count,
char *  out_buf 
)
inline

reads an uncounted array of characters

Usable for fixed-lenght entries. The buffer is not expected to contain a counter. Used with signature bytes.

Returns
true if all ok, false if out of buffer's bounds
bool bbb::ByteBuffer::readUncountedBytes ( int  count,
char *  out_buf 
)
inline

reads an uncounted array of characters

Usable for fixed-lenght entries. The buffer is not expected to contain a counter. Used with signature bytes.

Returns
true if all ok, false if out of buffer's bounds

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