libcommonc++  0.7
Blob Class Reference

A reference-counting, copy-on-write, threadsafe container for arbitrary binary data. More...

#include <Blob.h++>

Collaboration diagram for Blob:

Public Member Functions

 Blob ()
 Construct a new, empty Blob. More...
 
 Blob (byte_t *data, uint_t length, bool copy=true)
 Construct a new Blob from a byte array. More...
 
 Blob (const Blob &other)
 Copy constructor. More...
 
 Blob (const byte_t *data, uint_t length)
 Construct a new Blob from a byte array. More...
 
 ~Blob ()
 Destructor. More...
 
uint_t getLength () const
 Get the length of the Blob. More...
 
uint_t length () const
 Get the length of the Blob. More...
 
void setLength (uint_t length)
 Set the length of the Blob. More...
 
byte_tgetData ()
 Get a pointer to the beginning of the data in the Blob. More...
 
const byte_tgetData () const
 Get a pointer to the beginning of the data in the Blob. More...
 
Blobclear ()
 Clear the Blob. More...
 
bool isEmpty () const
 Test if the Blob is empty. More...
 
bool isNull () const
 Test if the Blob is null. More...
 
Blobappend (const byte_t *data, uint_t length)
 Append a byte array to the Blob. More...
 
Blobappend (const char *str, uint_t length=0)
 Append a character array to the Blob. More...
 
int indexOf (byte_t b, uint_t fromIndex=0) const
 Find the first occurrence of a given byte in the Blob. More...
 
int indexOf (const byte_t *buf, uint_t length, uint_t fromIndex=0) const
 Find the first occurrence of a given byte sequence in the Blob. More...
 
int lastIndexOf (byte_t b, uint_t fromIndex=END) const
 Find the last occurrence of a given byte in the Blob. More...
 
int lastIndexOf (const byte_t *buf, uint_t length, uint_t fromIndex=END) const
 Find the last occurrence of a given byte sequence in the Blob. More...
 
bool contains (byte_t b) const
 Determine if the Blob contains a given byte. More...
 
int compareTo (const Blob &other) const
 Compare this Blob to another. More...
 
Bloboperator= (const Blob &other)
 Assignment operator. More...
 
byte_toperator[] (int index)
 Array index operator. More...
 
byte_t operator[] (int index) const
 Array index operator. More...
 
bool operator! () const
 Unary NOT operator. More...
 
Bloboperator+= (byte_t b)
 Append a byte onto the end of the Blob. More...
 
Bloboperator+= (int v)
 Append a value onto the end of the Blob. More...
 
Bloboperator+= (const char *str)
 Append a character string onto the end of the Blob. More...
 
Bloboperator+= (const Blob &blob)
 Append (a copy of) the contents of another Blob onto the end of the Blob. More...
 
Bloboperator<< (byte_t val)
 Append operator. More...
 
Bloboperator<< (int val)
 Append operator. More...
 
Bloboperator<< (const char *str)
 Append operator. More...
 
uint_t hash (uint_t modulo=256) const
 Compute a hashcode for the Blob. More...
 

Static Public Attributes

static const Blob null
 The null Blob. More...
 
static const uint_t END = 0xFFFFFFFF
 A pseudo-index indicating the end of the blob. More...
 

Detailed Description

A reference-counting, copy-on-write, threadsafe container for arbitrary binary data.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ Blob() [1/4]

Blob ( )

Construct a new, empty Blob.

◆ Blob() [2/4]

Blob ( byte_t data,
uint_t  length,
bool  copy = true 
)

Construct a new Blob from a byte array.

Parameters
dataThe byte array to copy or inherit.
lengthThe length of the array.
copyIf true, the byte array is copied into the Blob; otherwise the byte array is inherited.

◆ Blob() [3/4]

Blob ( const Blob other)

Copy constructor.

◆ Blob() [4/4]

Blob ( const byte_t data,
uint_t  length 
)

Construct a new Blob from a byte array.

Parameters
dataThe array to copy.
lengthThe length of the array.

◆ ~Blob()

~Blob ( )

Destructor.

Member Function Documentation

◆ append() [1/2]

Blob & append ( const byte_t data,
uint_t  length 
)

Append a byte array to the Blob.

Parameters
dataThe array to append.
lengthThe length of the array.

◆ append() [2/2]

Blob & append ( const char *  str,
uint_t  length = 0 
)

Append a character array to the Blob.

Parameters
strThe array to append.
lengthThe number of characters from the string to append, or 0 to append the entire string (up to, but not including, the NUL terminator).

◆ clear()

Blob& clear ( )
inline

Clear the Blob.

Sets the length of the Blob to 0.

◆ compareTo()

int compareTo ( const Blob other) const

Compare this Blob to another.

Parameters
otherThe Blob to compare to.
Returns
A negative value if this Blob is "less" than other, a positive value if it is "greater" than other, and 0 if they are "equal".

◆ contains()

bool contains ( byte_t  b) const
inline

Determine if the Blob contains a given byte.

Parameters
bThe byte to search for.
Returns
true if the Blob contains at least one occurrence of the byte, false otherwise.

◆ getData() [1/2]

byte_t* getData ( )
inline

Get a pointer to the beginning of the data in the Blob.

◆ getData() [2/2]

const byte_t* getData ( ) const
inline

Get a pointer to the beginning of the data in the Blob.

◆ getLength()

uint_t getLength ( ) const
inline

Get the length of the Blob.

Returns
The length, in bytes, or 0 if the Blob is null.

◆ hash()

uint_t hash ( uint_t  modulo = 256) const

Compute a hashcode for the Blob.

Parameters
moduloThe desired range for the hashcode.
Returns
A hashcode in the range [0, modulo).

◆ indexOf() [1/2]

int indexOf ( byte_t  b,
uint_t  fromIndex = 0 
) const

Find the first occurrence of a given byte in the Blob.

Parameters
bThe byte to search for.
fromIndexThe start index from which to begin searching.
Returns
The index of the first occurrence of the byte, or -1 if the byte was not found.

◆ indexOf() [2/2]

int indexOf ( const byte_t buf,
uint_t  length,
uint_t  fromIndex = 0 
) const

Find the first occurrence of a given byte sequence in the Blob.

Parameters
bufThe buffer containing the byte sequence to search for.
lengthThe length of the sequence.
fromIndexThe start index from which to begin searching.
Returns
The index of the first occurrence of the byte sequence, or -1 if the sequence was not found.

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the Blob is empty.

Returns
true if the Blob is null or has length 0, false otherwise.

◆ isNull()

bool isNull ( ) const
inline

Test if the Blob is null.

Returns
true if the Blob is null, false otherwise.

◆ lastIndexOf() [1/2]

int lastIndexOf ( byte_t  b,
uint_t  fromIndex = END 
) const

Find the last occurrence of a given byte in the Blob.

Parameters
bThe byte to search for.
fromIndexThe index from which to begin searching backwards, or END to start at the end of the Blob.
Returns
The index of the last occurrence of the byte, or -1 if the byte was not found.

◆ lastIndexOf() [2/2]

int lastIndexOf ( const byte_t buf,
uint_t  length,
uint_t  fromIndex = END 
) const

Find the last occurrence of a given byte sequence in the Blob.

Parameters
bufThe buffer containing the byte sequence to search for.
lengthThe length of the sequence.
fromIndexThe index from which to begin searching backwards, or END to start at the end of the Blob.
Returns
The index of the last occurrence of the byte sequence, or -1 if the sequence was not found.

◆ length()

uint_t length ( ) const
inline

Get the length of the Blob.

Returns
The length, in bytes, or 0 if the Blob is null.

◆ operator!()

bool operator! ( ) const
inline

Unary NOT operator.

Returns
true if the Blob is null, false otherwise.

◆ operator+=() [1/4]

Blob& operator+= ( byte_t  b)
inline

Append a byte onto the end of the Blob.

Parameters
bThe byte to append.

◆ operator+=() [2/4]

Blob& operator+= ( int  v)
inline

Append a value onto the end of the Blob.

Parameters
vThe value to append. The value will be converted to a byte, which will then be appended to the blob.

◆ operator+=() [3/4]

Blob& operator+= ( const char *  str)
inline

Append a character string onto the end of the Blob.

Parameters
strThe string to append.

◆ operator+=() [4/4]

Blob& operator+= ( const Blob blob)
inline

Append (a copy of) the contents of another Blob onto the end of the Blob.

Parameters
blobThe Blob to append.

◆ operator<<() [1/3]

Blob& operator<< ( byte_t  val)
inline

Append operator.

◆ operator<<() [2/3]

Blob& operator<< ( int  val)
inline

Append operator.

◆ operator<<() [3/3]

Blob& operator<< ( const char *  str)
inline

Append operator.

◆ operator=()

Blob & operator= ( const Blob other)

Assignment operator.

◆ operator[]() [1/2]

byte_t & operator[] ( int  index)

Array index operator.

Obtain a reference to the byte at the given offset in the Blob.

Parameters
indexThe index.
Returns
A reference to the byte at the specified index.
Exceptions
OutOfBoundsExceptionIf index is out of range.

◆ operator[]() [2/2]

byte_t operator[] ( int  index) const

Array index operator.

Obtain a copy of the byte at the given offset in the Blob.

Parameters
indexThe index.
Returns
The byte at the specified index.
Exceptions
OutOfBoundsExceptionIf index is out of range.

◆ setLength()

void setLength ( uint_t  length)

Set the length of the Blob.

If the length is smaller than the current length, the Blob is truncated to the new length. If the new length is greater than the current length, the Blob is extended to the new length, and the new bytes are initialized to 0.

Parameters
lengthThe new length.

Member Data Documentation

◆ END

const uint_t END = 0xFFFFFFFF
static

A pseudo-index indicating the end of the blob.

◆ null

const Blob null
static

The null Blob.


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