#include <bit/data.h>
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 |
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.
uint8_t * bit::Data::data | ( | ) |
Pointer to the actual data.
References m_data_storage.
Referenced by bit::Int< I >::as_data(), bit::Float< F >::as_data(), bit::Buffer::clear_bits(), bit::FieldBuffer::data(), bit::Buffer::pack(), bit::Int< I >::set_value(), bit::Float< F >::set_value(), and bit::Buffer::unpack().
const uint8_t * bit::Data::data | ( | ) | const |
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
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 |
Current buffer size.
References m_data_storage.
Referenced by bit::Buffer::clear_bits(), bit::Buffer::pack(), bit::Int< I >::set_value(), bit::Float< F >::set_value(), and bit::Buffer::unpack().
size_t bit::Data::max_size | ( | ) | const |
void bit::Data::set_max_size | ( | size_t | ms | ) |
bool bit::Data::resize | ( | size_t | s | ) | throw (std::bad_alloc) |
Resize buffer to size s.
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 * | ( | ) |
bit::Data::operator const uint8_t * | ( | ) | const |
std::string bit::Data::encoded | ( | Encoding | en | ) | const |
Returns the specified string encoding of the data.
References base64(), dec(), bit::ENCODING_BASE64, bit::ENCODING_DEC, bit::ENCODING_HEX, bit::ENCODING_NONE, bit::ENCODING_OCT, bit::ENCODING_TYPE, hex(), m_data_storage, and oct().
Referenced by base64(), and bit::FieldBuffer::xml().
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 |
std::string bit::Data::oct | ( | std::string | separator = std::string() |
) | const |
std::string bit::Data::dec | ( | std::string | separator = std::string(" ") |
) | const |
bool bit::Data::set_data | ( | const std::string & | encoded, | |
Encoding | en | |||
) |
References bit::ENCODING_BASE64, bit::ENCODING_HEX, set_base64_data(), and set_hex_data().
bool bit::Data::set_base64_data | ( | const std::string & | encoded | ) |
bool bit::Data::set_hex_data | ( | const std::string & | encoded | ) |
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().
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>=().
DataStorage::pointer bit::Data::m_data_storage [protected] |
Referenced by base64(), clear(), clone(), compare(), data(), dec(), encoded(), hex(), max_size(), oct(), operator bool(), operator const uint8_t *(), operator uint8_t *(), resize(), set_data(), set_max_size(), and size().