conexus logo

Conexus::Data Class Reference

This structure represents a data chunk. More...

#include <data.h>

List of all members.

Classes

class  Storage

Public Member Functions

 Data (size_t s=0, unsigned priority=0) throw (std::bad_alloc)
 Constructor initializes buffer to a specific size.
 Data (const void *d, size_t s, unsigned priority=0, 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.
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.
 operator char * ()
 operator const char * () const
 operator void * ()
 operator const void * () const
uint8_t & operator[] (const ssize_t offset)
const uint8_t & operator[] (const ssize_t offset) const
std::string hex_string (std::string separator=std::string()) const
 Returns a hex string representation of the data.
void clear ()
 Releases any allocated memory and resets size to 0.
const TimeValtime () const
 Returns the timeval associated with this data item.
void set_time (const TimeVal &)
 Sets the timeval associated with this data item.
void set_current_time ()
 Sets the timeval associated with this data item to the current time.
unsigned priority () const
 Get the priority, where 0 is the lowest priority.
void set_priority (unsigned p)
 Set the priority, where 0 is the lowest priority.
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.
bool append (const Data &other)
 Appends a copy of the other data object to this data object.
Data operator+ (const Data &other) const
Dataoperator+= (const Data &other)

Protected Attributes

Storage::pointer m_storage


Detailed Description

This structure represents a data chunk.

Author:
Rick L Vinyard Jr
Examples:

anonymous_pipe.cpp, anonymous_pipe_server.cpp, factory_client.cpp, factory_server.cpp, file_client.cpp, file_eof.cpp, file_server.cpp, ipv4_multicast_client.cpp, ipv4_multicast_server.cpp, ipv4_tcp_client.cpp, ipv4_tcp_echo_client.cpp, ipv4_tcp_echo_server.cpp, ipv4_tcp_server.cpp, ipv4_udp_client.cpp, ipv4_udp_server.cpp, ipv4_udpposet_server.cpp, ipv6_multicast_client.cpp, ipv6_multicast_server.cpp, ipv6_tcp_client.cpp, ipv6_tcp_echo_client.cpp, ipv6_tcp_echo_server.cpp, ipv6_tcp_server.cpp, ipv6_udp_client.cpp, ipv6_udp_server.cpp, ipv6_udpposet_server.cpp, ll_client.cpp, ll_server.cpp, messagequeue_server.cpp, miniterm.cpp, registry_client.cpp, registry_server.cpp, and serial_send.cpp.


Constructor & Destructor Documentation

Conexus::Data::Data ( size_t  s = 0,
unsigned  priority = 0 
) throw (std::bad_alloc)

Constructor initializes buffer to a specific size.

Conexus::Data::Data ( const void *  d,
size_t  s,
unsigned  priority = 0,
DataMode  mode = COPY 
) throw (std::bad_alloc)

Constructor initializes buffer with a copy of specific data.

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

Conexus::Data::Data ( const Data other  ) 

Copy constructor.

Conexus::Data::~Data (  ) 

Destructor.


Member Function Documentation

bool Conexus::Data::append ( const Data other  ) 

Appends a copy of the other data object to this data object.

Returns:
true if successful, false otherwise

References data(), resize(), and size().

Referenced by operator+(), and operator+=().

void Conexus::Data::clear (  ) 

Releases any allocated memory and resets size to 0.

References m_storage.

Data Conexus::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 Conexus::COPY, and m_storage.

Referenced by operator+().

int Conexus::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_storage.

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

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

Constant pointer to the actual data.

References m_storage.

uint8_t * Conexus::Data::data (  ) 

std::string Conexus::Data::hex_string ( std::string  separator = std::string()  )  const

Conexus::Data::operator bool (  )  const

References m_storage.

Conexus::Data::operator bool (  ) 

References m_storage.

Conexus::Data::operator char * (  ) 

References m_storage.

Conexus::Data::operator const char * (  )  const

References m_storage.

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

Cast to a 1-octet const pointer.

References m_storage.

Conexus::Data::operator const void * (  )  const

References m_storage.

Conexus::Data::operator uint8_t * (  ) 

Cast to a 1-octet pointer.

References m_storage.

Conexus::Data::operator void * (  ) 

References m_storage.

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

References compare().

Data Conexus::Data::operator+ ( const Data other  )  const

References append(), and clone().

Data & Conexus::Data::operator+= ( const Data other  ) 

References append().

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

References compare().

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

References compare().

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

References compare().

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

References compare().

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

References compare().

const uint8_t & Conexus::Data::operator[] ( const ssize_t  offset  )  const

References m_storage.

uint8_t & Conexus::Data::operator[] ( const ssize_t  offset  ) 

References m_storage.

unsigned Conexus::Data::priority (  )  const

Get the priority, where 0 is the lowest priority.

References m_storage.

bool Conexus::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

Referenced by append(), Conexus::MessageQueue::read_data(), Conexus::SSL::IPv6::TCP::read_data(), Conexus::SSL::IPv4::UDP::read_data(), Conexus::SSL::IPv4::TCP::read_data(), Conexus::NSPR::FileDescriptor::read_data(), and Conexus::SSL::SSL::ssl_read().

void Conexus::Data::set_current_time (  ) 

bool Conexus::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 Conexus::COPY, Conexus::MANAGED, and Conexus::UNMANAGED.

void Conexus::Data::set_priority ( unsigned  p  ) 

Set the priority, where 0 is the lowest priority.

References m_storage.

void Conexus::Data::set_time ( const TimeVal t  ) 

Sets the timeval associated with this data item.

References m_storage.

size_t Conexus::Data::size (  )  const

const TimeVal & Conexus::Data::time (  )  const

Returns the timeval associated with this data item.

References m_storage.


Member Data Documentation


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

Generated on Wed Jul 8 15:51:17 2009 for conexus by doxygen 1.5.8