YAPET::Record< T > Class Template Reference

Template for allocating/deallocating memory for structs. More...

#include <record.h>

List of all members.

Public Member Functions

const T * getData () const
 Get the pointer to the struct.
T * getData ()
 Get the pointer to the struct.
 operator const T * () const
 Cast to the pointer of the struct.
 operator const uint8_t * () const
 Cast operator.
 operator T * ()
 Cast to the pointer of the struct.
 operator uint8_t * ()
 Cast operator.
const Record< T > & operator= (const BDBuffer &bdb) throw (YAPETException)
 Assignment operator.
const Record< T > & operator= (const T *r) throw (YAPETException)
 Assignment operator.
const Record< T > & operator= (const T &r) throw (YAPETException)
 Assignment operator.
const Record< T > & operator= (const Record< T > &r) throw (YAPETException)
 Assignment operator.
 Record (const Record< T > &r) throw (YAPETException)
 Record () throw (YAPETException)
 Allocates memory to hold a struct of the type T.
 Record (const T &d) throw (YAPETException)
 Allocates memory.
uint32_t size () const
 Get the size of the allocated memory.
virtual ~Record ()

Private Member Functions

void alloc_mem () throw (YAPETException)
 Allocate memory for the struct.
void free_mem ()
 Zero out and free memory.

Private Attributes

uint32_t _size
 The size of the memory allocated.
T * data
 Pointer to the struct.


Detailed Description

template<class T>
class YAPET::Record< T >

The primary intend of this template is to make sure the memory allocated for a struct is zero'ed out upon deallocation.

The template allocates enough memory on the heap for holding the struct of type T.

It allows direct manipulation of the struct on the heap.

Definition at line 71 of file record.h.


Constructor & Destructor Documentation

template<class T>
YAPET::Record< T >::Record ( const T &  d  )  throw (YAPETException) [inline]

Allocates memory of the proper size and copies the content of the given struct d.

Parameters:
d reference to the struct from where the content is copied to the allocated memory.

template<class T>
YAPET::Record< T >::Record (  )  throw (YAPETException) [inline]

Allocates memory to hold a struct of the type T.

template<class T>
YAPET::Record< T >::Record ( const Record< T > &  r  )  throw (YAPETException) [inline]

template<class T>
virtual YAPET::Record< T >::~Record (  )  [inline, virtual]


Member Function Documentation

template<class T>
void YAPET::Record< T >::alloc_mem (  )  throw (YAPETException) [inline, private]

Allocates the proper amount of memory for holding the struct and sets the _size field.

Definition at line 93 of file record.h.

References YAPET::Record< T >::_size, and YAPET::Record< T >::data.

Referenced by YAPET::Record< T >::operator=().

template<class T>
void YAPET::Record< T >::free_mem (  )  [inline, private]

Zero'es the memory out and frees it.

Definition at line 106 of file record.h.

References YAPET::Record< T >::_size, and YAPET::Record< T >::data.

Referenced by YAPET::Record< T >::operator=().

template<class T>
const T* YAPET::Record< T >::getData (  )  const [inline]

Gets the pointer to the struct on the heap.

Returns:
pointer to the struct on the heap.

Definition at line 167 of file record.h.

References YAPET::Record< T >::data.

template<class T>
T* YAPET::Record< T >::getData (  )  [inline]

Gets the pointer to the struct on the heap.

Returns:
pointer to the struct on the heap.

Definition at line 159 of file record.h.

References YAPET::Record< T >::data.

template<class T>
YAPET::Record< T >::operator const T * (  )  const [inline]

Cast to the pointer of the struct on the heap.

Returns:
pointer to the struct on the heap.

Definition at line 184 of file record.h.

References YAPET::Record< T >::data.

template<class T>
YAPET::Record< T >::operator const uint8_t * (  )  const [inline]

Cast operator used by the openssl functions.

Returns:
pointer to the struct casted to an unsigned 8 bits integer pointer.

Definition at line 202 of file record.h.

References YAPET::Record< T >::data.

template<class T>
YAPET::Record< T >::operator T * (  )  [inline]

Cast to the pointer of the struct on the heap.

Returns:
pointer to the struct on the heap.

Definition at line 176 of file record.h.

References YAPET::Record< T >::data.

template<class T>
YAPET::Record< T >::operator uint8_t * (  )  [inline]

Cast operator used by the openssl functions.

Returns:
pointer to the struct casted to an unsigned 8 bits integer pointer.

Definition at line 193 of file record.h.

References YAPET::Record< T >::data.

template<class T>
const Record<T>& YAPET::Record< T >::operator= ( const BDBuffer bdb  )  throw (YAPETException) [inline]

Assigns a BDBuffer. If the size of the BDBuffer is smaller than the size of the struct, an exception is thrown.

Only as much bytes as fit into struct are copied from the BDBuffer.

Parameters:
bdb reference to a BDBuffer.
Returns:
const reference to this.

Definition at line 275 of file record.h.

References YAPET::Record< T >::_size, YAPET::Record< T >::alloc_mem(), YAPET::Record< T >::data, and YAPET::Record< T >::free_mem().

template<class T>
const Record<T>& YAPET::Record< T >::operator= ( const T *  r  )  throw (YAPETException) [inline]

Assigns a struct of type T to this.

Parameters:
r pointer to a struct of type T.
Returns:
const reference to this.

Definition at line 253 of file record.h.

References YAPET::Record< T >::_size, YAPET::Record< T >::alloc_mem(), YAPET::Record< T >::data, and YAPET::Record< T >::free_mem().

template<class T>
const Record<T>& YAPET::Record< T >::operator= ( const T &  r  )  throw (YAPETException) [inline]

Assigns a struct of type T to this.

Parameters:
r reference to a struct of type T.
Returns:
const reference to this.

Definition at line 235 of file record.h.

References YAPET::Record< T >::_size, YAPET::Record< T >::alloc_mem(), YAPET::Record< T >::data, and YAPET::Record< T >::free_mem().

template<class T>
const Record<T>& YAPET::Record< T >::operator= ( const Record< T > &  r  )  throw (YAPETException) [inline]

Assigns another Record to this.

Parameters:
r reference to a Record.
Returns:
const reference to this.

Definition at line 213 of file record.h.

References YAPET::Record< T >::alloc_mem(), YAPET::Record< T >::data, and YAPET::Record< T >::free_mem().

template<class T>
uint32_t YAPET::Record< T >::size (  )  const [inline]

Get the size of the allocated memory.

Definition at line 150 of file record.h.

References YAPET::Record< T >::_size.


Member Data Documentation

template<class T>
uint32_t YAPET::Record< T >::_size [private]

The size of the memory allocated. Used to zero out the memory used by the struct.

Definition at line 79 of file record.h.

Referenced by YAPET::Record< T >::alloc_mem(), YAPET::Record< T >::free_mem(), YAPET::Record< T >::operator=(), and YAPET::Record< T >::size().

template<class T>
T* YAPET::Record< T >::data [private]


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

Generated on Thu Jun 11 19:13:06 2009 for YAPET by  doxygen 1.5.8