Blob Class Reference

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

#include <Blob.h++>

Collaboration diagram for Blob:

Collaboration graph
[legend]

List of all members.

Classes

class  BlobBuf

Public Member Functions

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

Static Public Attributes

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


Detailed Description

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

Author:
Mark Lindner

Constructor & Destructor Documentation

Blob (  )  throw ()

Construct a new, empty Blob.

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

Construct a new Blob from a byte array.

Parameters:
data The byte array to copy or inherit.
length The length of the array.
copy If true, the byte array is copied into the Blob; otherwise the byte array is inherited.

Blob ( const Blob other  ) 

Copy constructor.

Blob ( const byte_t data,
size_t  length 
)

Construct a new Blob from a byte array.

Parameters:
data The array to copy.
length The length of the array.

~Blob (  )  throw ()

Destructor.


Member Function Documentation

Blob & append ( const char *  str,
size_t  len = 0 
)

Append a character array to the Blob.

Parameters:
str The array to append.
len The number of characters from the string to append, or 0 to append the entire string (up to, but not including, the NUL terminator).

Blob & append ( const byte_t data,
size_t  len 
)

Append a byte array to the Blob.

Parameters:
data The array to append.
len The length of the array.

Blob& clear (  )  [inline]

Clear the Blob.

Sets the length of the Blob to 0.

int compareTo ( const Blob other  )  const throw ()

Compare this Blob to another.

Parameters:
other The 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".

bool contains ( byte_t  b  )  const throw () [inline]

Determine if the Blob contains a given byte.

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

const byte_t* getData (  )  const throw () [inline]

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

byte_t* getData (  )  throw () [inline]

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

size_t getLength (  )  const throw () [inline]

Get the length of the Blob.

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

uint_t hash ( uint_t  modulo = 256  )  const throw ()

Compute a hashcode for the Blob.

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

int indexOf ( const byte_t buf,
size_t  len,
uint_t  fromIndex = 0 
) const throw ()

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

Parameters:
buf The buffer containing the byte sequence to search for.
len The length of the sequence.
fromIndex The 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.

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

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

Parameters:
b The byte to search for.
fromIndex The 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.

bool isEmpty (  )  const throw () [inline]

Test if the Blob is empty.

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

bool isNull (  )  const throw () [inline]

Test if the Blob is null.

Returns:
true if the Blob is null, false otherwise.

int lastIndexOf ( const byte_t buf,
size_t  len,
uint_t  fromIndex = END 
) const throw ()

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

Parameters:
buf The buffer containing the byte sequence to search for.
len The length of the sequence.
fromIndex The 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.

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

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

Parameters:
b The byte to search for.
fromIndex The 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.

size_t length (  )  const throw () [inline]

Get the length of the Blob.

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

bool operator! (  )  const throw () [inline]

Unary NOT operator.

Returns:
true if the Blob is null, false otherwise.

Blob& operator+= ( const Blob blob  )  [inline]

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

Parameters:
blob The Blob to append.

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

Append a character string onto the end of the Blob.

Parameters:
str The string to append.

Blob& operator+= ( int  v  )  [inline]

Append a value onto the end of the Blob.

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

Blob& operator+= ( byte_t  b  )  [inline]

Append a byte onto the end of the Blob.

Parameters:
b The byte to append.

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

Append operator.

Blob& operator<< ( int  val  )  [inline]

Append operator.

Blob& operator<< ( byte_t  val  )  [inline]

Append operator.

Blob & operator= ( const Blob other  ) 

Assignment operator.

byte_t operator[] ( int  index  )  const throw (OutOfBoundsException)

Array index operator.

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

Parameters:
index The index.
Returns:
The byte at the specified index.
Exceptions:
OutOfBoundsException If index is out of range.

byte_t & operator[] ( int  index  )  throw (OutOfBoundsException)

Array index operator.

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

Parameters:
index The index.
Returns:
A reference to the byte at the specified index.
Exceptions:
OutOfBoundsException If index is out of range.

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:
length The new length.


Member Data Documentation

const uint_t END = 0xFFFFFFFF [static]

A pseudo-index indicating the end of the blob.

const Blob null [static]

The null Blob.


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

Generated on Mon Jan 4 21:38:47 2010 for libcommonc++ by  doxygen 1.5.9