GNUMessenger::VBuffer Class Reference

A vector based byte buffer class. More...

#include <buffer.h>

Collaboration diagram for GNUMessenger::VBuffer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 VBuffer ()
 Default. The internal vector has length zero.
 ~VBuffer ()
 "Secure" deallocator.
 VBuffer (const string &str)
 String constructor.
 VBuffer (const char *str, unsigned long length)
 Constant character array constructor.
 VBuffer (const VBuffer &buf)
 Copy constructor.
 VBuffer (byte *str, unsigned long length)
 Byte array constructor.
void wipe ()
const byte * data () const
 Returns the data in the vector as a constant byte array Time complexity: Approx.
VBuffer operator+ (const VBuffer &buf)
 VBuffer addition, returns a new VBuffer that is the union of two VBuffers.
VBufferoperator= (const VBuffer &buf)
 Assignment operator.
VBufferoperator+= (const VBuffer &buf)
 Concatination operator.
VBufferoperator+= (const byte &b)
 Appends a byte to the end of the vector.
VBuffer sub (unsigned long start, unsigned long length=0) const
 Extracts a range of elements.

Detailed Description

A vector based byte buffer class.

Author:
Jesse Lovelace

Definition at line 37 of file buffer.h.


Constructor & Destructor Documentation

GNUMessenger::VBuffer::~VBuffer  )  [inline]
 

"Secure" deallocator.

Of course, this does not do anything if the memory was swapped to disk Definition at line 46 of file buffer.h.

References GNUMessenger::scoped_array< T >::get().

00047 { 00048 zero(); 00049 00050 if (m_data.get()) 00051 memset(m_data.get(), 0, m_size * sizeof(byte)); 00052 }

Here is the call graph for this function:

GNUMessenger::VBuffer::VBuffer const string &  str  )  [inline]
 

String constructor.

Parameters:
str The VBuffer copies the string into the byte vector, this is a deep copy.
Definition at line 57 of file buffer.h.
00057 :vector<byte>(str.length()) { 00058 for ( unsigned int i = 0; i < str.length(); i++) 00059 (*this)[i] = ((byte)str[i]); 00060 }

GNUMessenger::VBuffer::VBuffer const char *  str,
unsigned long  length
[inline]
 

Constant character array constructor.

This is a deep copy.

Parameters:
str A constant pointer to an array of characters The length of the character array
Definition at line 65 of file buffer.h.
00065 :vector<byte>(length) 00066 { 00067 for ( unsigned int i = 0; i < length; i++) 00068 (*this)[i] = ((byte)str[i]); 00069 00070 }

GNUMessenger::VBuffer::VBuffer const VBuffer buf  )  [inline]
 

Copy constructor.

Parameters:
buf This copies the VBuffer.
Definition at line 74 of file buffer.h.
00074 :vector<byte>() 00075 { 00076 reserve(buf.size()); 00077 insert(end(), buf.begin(), buf.end()); 00078 }

GNUMessenger::VBuffer::VBuffer byte *  str,
unsigned long  length
[inline]
 

Byte array constructor.

Parameters:
str A pointer to byte array.
length The length of the byte array
Definition at line 83 of file buffer.h.
00083 :vector<byte>(length) 00084 { 00085 for ( unsigned int i = 0; i < length; i++) 00086 (*this)[i] = (str[i]); 00087 00088 }


Member Function Documentation

const byte* GNUMessenger::VBuffer::data  )  const [inline]
 

Returns the data in the vector as a constant byte array Time complexity: Approx.

O(N)

Returns:
Constant byte array.
Definition at line 99 of file buffer.h.

References GNUMessenger::scoped_array< T >::get(), and GNUMessenger::scoped_array< T >::reset().

00099 { 00100 vector<byte>::const_iterator it = begin(); 00101 00102 // zero old buffer data 00103 if (m_data.get()) 00104 memset(m_data.get(), 0,m_size * sizeof(byte)); 00105 00106 m_size = static_cast<unsigned long>(size()); 00107 m_data.reset( new byte[size()] ); 00108 00109 for (unsigned long i = 0; i < size(); i++) 00110 { 00111 m_data[i] = *it; 00112 it++; 00113 } 00114 00115 return m_data.get(); 00116 }

Here is the call graph for this function:

VBuffer GNUMessenger::VBuffer::operator+ const VBuffer buf  )  [inline]
 

VBuffer addition, returns a new VBuffer that is the union of two VBuffers.

Parameters:
buf The VBuffer to union with this VBuffer
Returns:
A new VBuffer object
Note:
This is a costly operation and should be avoided if possible.
Definition at line 126 of file buffer.h.
00127 { 00128 VBuffer tmp(*this); 00129 tmp.insert(tmp.end(), buf.begin(), buf.end()); 00130 return tmp; 00131 }

VBuffer& GNUMessenger::VBuffer::operator+= const VBuffer buf  )  [inline]
 

Concatination operator.

Parameters:
buf VBuffer to append to the current VBuffer
Definition at line 146 of file buffer.h.
00147 { 00148 reserve(size() + buf.size()); 00149 insert(end(), buf.begin(), buf.end()); 00150 return *this; 00151 }


The documentation for this class was generated from the following file:
Generated on Tue Oct 5 14:41:48 2004 for GNU Messenger by doxygen 1.3.8