seven bits

bit::Data Class Reference
["Data Buffers"]

#include <bit/data.h>

Inheritance diagram for bit::Data:

bit::Buffer bit::RecordBuffer

List of all members.


Detailed Description

This structure represents a data chunk of octets.

Author:
Rick L Vinyard Jr

Public Member Functions

 Data (size_t s=0) throw (std::bad_alloc)
 Constructor initializes buffer to a specific size.
 Data (const void *d, size_t s, DataMode mode=COPY) throw (std::bad_alloc)
 Constructor initializes buffer with a copy of specific data.
 Data (const Data &other)
 Copy constructor.
 ~Data ()
 Destructor.
uint8_t * data ()
 Pointer to the actual data.
const uint8_t * data () const
 Constant pointer to the actual data.
bool set_data (const void *newdata, size_t newsize, DataMode mode=COPY) throw (std::bad_alloc)
 Sets the buffer to specific data.
size_t size () const
 Current buffer size.
size_t max_size () const
 Maximum size buffer is allowed to grow to, or 0 if unlimited.
void set_max_size (size_t ms)
 Set the maximum size buffer is allowed to grow to, or 0 if unlimited.
bool resize (size_t s) throw (std::bad_alloc)
 Resize buffer to size s.
Data clone () const
 Performs a deep copy of this data object.
 operator bool ()
 operator bool () const
 operator uint8_t * ()
 Cast to a 1-octet pointer.
 operator const uint8_t * () const
 Cast to a 1-octet const pointer.
std::string encoded (Encoding en) const
 Returns the specified string encoding of the data.
std::string base64 () const
 Returns a base64 string encoding of the data.
std::string hex (std::string separator=std::string()) const
 Returns a hex string encoding of the data.
std::string oct (std::string separator=std::string()) const
 Returns an octal string encoding of the data.
std::string dec (std::string separator=std::string(" ")) const
 Returns a decimal string encoding of the data.
bool set_data (const std::string &encoded, Encoding en)
bool set_base64_data (const std::string &encoded)
bool set_hex_data (const std::string &encoded)
void clear ()
 Releases any allocated memory and resets size to 0.
bool operator< (const Data &other) const
bool operator<= (const Data &other) const
bool operator== (const Data &other) const
bool operator!= (const Data &other) const
bool operator>= (const Data &other) const
bool operator> (const Data &other) const
int compare (const Data &other) const
 Similar to memcmp.

Protected Attributes

DataStorage::pointer m_data_storage

Classes

class  DataStorage

Constructor & Destructor Documentation

bit::Data::Data ( size_t  s = 0  )  throw (std::bad_alloc)

Constructor initializes buffer to a specific size.

bit::Data::Data ( const void *  d,
size_t  s,
DataMode  mode = COPY 
) throw (std::bad_alloc)

Constructor initializes buffer with a copy of specific data.

References bit::COPY, bit::MANAGED, and bit::UNMANAGED.

bit::Data::Data ( const Data other  ) 

Copy constructor.

bit::Data::~Data (  ) 

Destructor.


Member Function Documentation

uint8_t * bit::Data::data (  ) 

const uint8_t * bit::Data::data (  )  const

Constant pointer to the actual data.

References m_data_storage.

bool bit::Data::set_data ( const void *  newdata,
size_t  newsize,
DataMode  mode = COPY 
) throw (std::bad_alloc)

Sets the buffer to specific data.

newdata + newsize must not be within the current storage region if a copy is performed

Returns:
false if a realloc is required and the realloc fails

References clear(), bit::COPY, m_data_storage, bit::MANAGED, and bit::UNMANAGED.

Referenced by set_base64_data(), and set_hex_data().

size_t bit::Data::size (  )  const

size_t bit::Data::max_size (  )  const

Maximum size buffer is allowed to grow to, or 0 if unlimited.

References m_data_storage.

void bit::Data::set_max_size ( size_t  ms  ) 

Set the maximum size buffer is allowed to grow to, or 0 if unlimited.

References m_data_storage.

bool bit::Data::resize ( size_t  s  )  throw (std::bad_alloc)

Resize buffer to size s.

Returns:
true on success, false on failure
  • If s < current size, then buffer is shrunk
  • If s > current size, then buffer is expanded and zero-filled
  • If s = current size, no changes occur
  • If currently set to an external buffer, this method will fail

References clear(), and m_data_storage.

Referenced by bit::Buffer::pack(), and bit::Buffer::unpack().

Data bit::Data::clone (  )  const

Performs a deep copy of this data object.

This method allocates a new memory chunk, copies the existing data into that data chunk, and returns an object containing a smart pointer to the underlying data.

References bit::COPY, and m_data_storage.

bit::Data::operator bool (  ) 

References m_data_storage.

bit::Data::operator bool (  )  const

References m_data_storage.

bit::Data::operator uint8_t * (  ) 

Cast to a 1-octet pointer.

References m_data_storage.

bit::Data::operator const uint8_t * (  )  const

Cast to a 1-octet const pointer.

References m_data_storage.

std::string bit::Data::encoded ( Encoding  en  )  const

std::string bit::Data::base64 (  )  const

Returns a base64 string encoding of the data.

References encoded(), and m_data_storage.

Referenced by encoded().

std::string bit::Data::hex ( std::string  separator = std::string()  )  const

Returns a hex string encoding of the data.

References m_data_storage.

Referenced by encoded().

std::string bit::Data::oct ( std::string  separator = std::string()  )  const

Returns an octal string encoding of the data.

References m_data_storage.

Referenced by encoded().

std::string bit::Data::dec ( std::string  separator = std::string(" ")  )  const

Returns a decimal string encoding of the data.

References m_data_storage.

Referenced by encoded().

bool bit::Data::set_data ( const std::string &  encoded,
Encoding  en 
)

bool bit::Data::set_base64_data ( const std::string &  encoded  ) 

References set_data().

Referenced by set_data().

bool bit::Data::set_hex_data ( const std::string &  encoded  ) 

References set_data().

Referenced by set_data().

void bit::Data::clear (  ) 

Releases any allocated memory and resets size to 0.

References m_data_storage.

Referenced by resize(), set_data(), and bit::Buffer::unpack().

bool bit::Data::operator< ( const Data other  )  const

References compare().

bool bit::Data::operator<= ( const Data other  )  const

References compare().

bool bit::Data::operator== ( const Data other  )  const

References compare().

bool bit::Data::operator!= ( const Data other  )  const

References compare().

bool bit::Data::operator>= ( const Data other  )  const

References compare().

bool bit::Data::operator> ( const Data other  )  const

References compare().

int bit::Data::compare ( const Data other  )  const

Similar to memcmp.

Compares the memory areas of two data items. If the two data items are of different sizes (s1 and s2) only the first n bytes will be compared, where n is the lesser of s1 and s2.

Unlike memcmp, 0 will be returned only if the memory areas are identical and s1 is equal to s2.

If memcmp would return 0 for the first n bytes and s1 != s2, the an integer less than 0 is returned if s1 < s2 and an integer greater than 0 is returned if s1 > s2.

References m_data_storage.

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().


Member Data Documentation


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

Generated on Mon Nov 3 10:50:01 2008 for bit by doxygen 1.5.6