Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBrawBuffer Class Template Reference

Raw memory manager. More...

#include <CTBrawBuffer.hxx>

Inheritance diagram for CTBrawBuffer:

Inheritance graph
[legend]
Collaboration diagram for CTBrawBuffer:

Collaboration graph
[legend]
List of all members.

Public Methods

 CTBrawBuffer ()
 CTBrawBuffer (CTBint i_capacity)
 CTBrawBuffer (CTBrawBuffer< T > &rhs, bool b_grab)
 ~CTBrawBuffer ()
void Construct (CTBint i_ind)
void Construct (T *p_ele)
void ConstructRange (CTBint i_beg, CTBint i_size)
void Construct (CTBint i_ind, const T &value)
void Construct (T *p_ele, const T &value)
void ConstructRange (CTBint i_beg, CTBint i_size, const T &value)
void ConstructRange (CTBint i_beg, CTBint i_size, const T rhs[])
void Destruct (CTBint i_ind)
void Destruct (T *p_ele)
void DestructRange (CTBint i_beg, CTBint i_size)
void GrabConstruct (CTBint i_ind, T &value)
void GrabConstructRange (CTBint i_beg, CTBint i_size, T rhs[])
void GrabDestruct (CTBint i_ind, T &obj)
CTBint Capacity () const
void Resize (CTBint i_capacity)
void Grab (CTBrawBuffer< T > &rhs)
bool Empty () const
void ShiftRight (CTBint i_beg, CTBint i_end)
void ShiftLeft (CTBint i_beg, CTBint i_end)
void Copy (CTBint i_beg, CTBint i_size, const T &rhs)
void Copy (CTBint i_beg, CTBint i_size, const T rhs[])
void Dump (int i_indent=0, ostream &os=cout, const char *p_text=0) const
Toperator+ (CTBint i_ind)
const Toperator+ (CTBint i_ind) const
Toperator[] (CTBint i_ind)
const Toperator[] (CTBint i_ind) const
bool operator! () const
 operator T * ()
 operator const T * () const

Private Methods

void DeleteBuffer ()
void CreateBuffer (CTBint i_capacity)
 CTBrawBuffer (const CTBrawBuffer< T > &rhs)
CTBrawBuffer< T > & operator= (const CTBrawBuffer< T > &rhs)

Private Attributes

Tmp_data
CTBint mi_capacity

Detailed Description

template<class T>
class CTBrawBuffer< T >

Raw memory manager.

CTBrawBuffer manages a buffer of raw memory and provides member functions for constructing and destructing objects in this raw memory area. This class is mainly used in the implementation of containers, like for example CTBvector.

Note, that CTBrawBuffer keeps only track of the amount of allocated raw memory, but does not track in which areas objects have been actually constructed. Therefore, it is the responsibility of the caller to destruct all constructed objects before a CTBrawBuffer is destroyed.

Note, that CTBrawBuffer objects are neither copyable and nor assignable ! This is because a CTBrawBuffer object doesn't know which buffer elements have been constructed into an object and which ones are still raw memory. If a class has a member variable of type CTBrawBuffer it has to explicitely implement a copy contructor and assignment operator which copies the constructed buffer elements, for example using the Copy() function.

A copy constructor and an assigment operator is defined as private member function, but not implemented to prevent usage of the compiler generated functions.

Requirements:

Definition at line 19 of file CTBrawBuffer.hxx.


Constructor & Destructor Documentation

template<class T>
CTBrawBuffer< T >::CTBrawBuffer [inline]
 

Default constructor.

Constructs an empty CTBrawBuffer object. No memory is allocated.

Definition at line 61 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::CTBrawBuffer CTBint i_capacity [inline, explicit]
 

Construct with given capacity.

Constructs an CTBrawBuffer object with space for i_capacity objects of type T.

Definition at line 74 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::CTBrawBuffer CTBrawBuffer< T > & rhs,
bool b_grab
[inline]
 

Grab constructor.

Definition at line 85 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::~CTBrawBuffer [inline]
 

Destructor.

Will release the raw memory previously allocated by this object. Note, that the objects constructed within the raw memory must have been destructed before the destructor of the CTBrawBuffer object is called.

Definition at line 102 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::CTBrawBuffer const CTBrawBuffer< T > & rhs [private]
 


Member Function Documentation

template<class T>
void CTBrawBuffer< T >::Construct CTBint i_ind [inline]
 

Default construct element.

The buffer element with index i_ind is constructed into an object of type T with the default constructor.

Definition at line 115 of file CTBrawBuffer.icc.

Referenced by CTBvector::Insert(), CTBvector::InsertTail(), CTBvector::operator=(), and CTBmatrix::operator=().

template<class T>
void CTBrawBuffer< T >::Construct T * p_ele [inline]
 

Default construct element.

The buffer element pointed to by p_ele is constructed into an object of type T with the default constructor.

Definition at line 130 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::ConstructRange CTBint i_beg,
CTBint i_size
[inline]
 

Default construct element range.

The i_size buffer elements starting at index i_beg are constructed into objects of type T with the default constructor.

Definition at line 145 of file CTBrawBuffer.icc.

Referenced by CTBmatrix::CTBmatrix(), CTBvector::CTBvector(), CTBvector::Resize(), CTBmatrix::Resize(), CTBvector::operator=(), and CTBmatrix::operator=().

template<class T>
void CTBrawBuffer< T >::Construct CTBint i_ind,
const T & value
[inline]
 

Copy construct element.

The buffer element with index i_ind is constructed into an object of type T with the copy constructor duplicating value.

Definition at line 162 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::Construct T * p_ele,
const T & value
[inline]
 

Copy construct element.

The buffer element pointed to by p_ele is constructed into an object of type T with the copy constructor duplicating value.

Definition at line 177 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::ConstructRange CTBint i_beg,
CTBint i_size,
const T & value
[inline]
 

Construct element range from scalar.

i_size buffer elements starting at index i_beg are constructed into objects of type T with the copy constructor duplicating value.

Definition at line 192 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::ConstructRange CTBint i_beg,
CTBint i_size,
const T rhs[]
[inline]
 

Construct element range from array.

i_size buffer elements starting at index i_beg are constructed into objects of type T with the copy constructor duplicating the first i_size elements of array rhs.

Definition at line 211 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::Destruct CTBint i_ind [inline]
 

The buffer element with index i_ind is destructed.

Definition at line 225 of file CTBrawBuffer.icc.

Referenced by CTBvector::ChangeCapacity(), CTBmatrix::ChangeCapacity(), and CTBvector::Delete().

template<class T>
void CTBrawBuffer< T >::Destruct T * p_ele [inline]
 

The buffer element pointed to by p_ele is destructed.

Definition at line 235 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::DestructRange CTBint i_beg,
CTBint i_size
[inline]
 

The i_size buffer elements starting at index i_beg are destrucuted.

Definition at line 246 of file CTBrawBuffer.icc.

Referenced by CTBvector::Grab(), CTBmatrix::Grab(), CTBvector::Resize(), CTBmatrix::Resize(), CTBvector::operator=(), CTBmatrix::operator=(), CTBmatrix::~CTBmatrix(), and CTBvector::~CTBvector().

template<class T>
void CTBrawBuffer< T >::GrabConstruct CTBint i_ind,
T & value
[inline]
 

'Grab or copy' construct element with index i_ind from value.

Definition at line 259 of file CTBrawBuffer.icc.

Referenced by CTBvector::ChangeCapacity(), and CTBmatrix::ChangeCapacity().

template<class T>
void CTBrawBuffer< T >::GrabConstructRange CTBint i_beg,
CTBint i_size,
T rhs[]
[inline]
 

'Garb or copy' construct element range from array.

i_size buffer elements starting at index i_beg are constructed into objects of type T with the copy constructor grabing of copying the first i_size elements of array rhs.

Definition at line 277 of file CTBrawBuffer.icc.

Referenced by CTBmatrix::Resize().

template<class T>
void CTBrawBuffer< T >::GrabDestruct CTBint i_ind,
T & obj
[inline]
 

'Grab or copy' to obj the element with index i_ind, than destroy it.

Definition at line 292 of file CTBrawBuffer.icc.

Referenced by CTBvector::RemoveTail().

template<class T>
CTBint CTBrawBuffer< T >::Capacity const [inline]
 

Returns the capacity.

The capacity is the size of the allocated raw memory buffer in units of objects of type T. The capacity can be set at construction time or changed later on with Resize().

Definition at line 310 of file CTBrawBuffer.icc.

Referenced by CTBvector::Capacity(), CTBmatrix::Capacity(), CTBvector::Grab(), CTBmatrix::Grab(), CTBmatrix::~CTBmatrix(), and CTBvector::~CTBvector().

template<class T>
void CTBrawBuffer< T >::Resize CTBint i_capacity [inline]
 

Change capacity of buffer.

This function simply releases the old buffer and allocates a new one with a capacity of i_capacity. Therefore, all constructed objects must have been destructed before Resize() is called.

Definition at line 324 of file CTBrawBuffer.icc.

Referenced by CTBvector::ChangeCapacity(), CTBmatrix::ChangeCapacity(), CTBvector::Grab(), CTBmatrix::Grab(), and CTBmatrix::Resize().

template<class T>
void CTBrawBuffer< T >::Grab CTBrawBuffer< T > & rhs [inline]
 

Grab resources.

The resources allocated for rhs will be transfered to the calling object. Note, that the object must be in Empty() state and that rhs must be a different object. In most other classes the grab method is protected against these cases, but in CTBrawBuffer this is not possible because the class does not keep track in which areas objects have been actually constructed.

Definition at line 343 of file CTBrawBuffer.icc.

Referenced by CTBvector::Grab(), CTBmatrix::Grab(), and CTBmatrix::Resize().

template<class T>
bool CTBrawBuffer< T >::Empty const [inline]
 

Returns true if no buffer allocated.

A CTBrawBuffer object is empty after is has been constructed with the default constructor, or with a capacity of 0, or has been resized to a capacity of 0. It's also empty after it has been grabbed, either with a grab constructor or with Grab().

Definition at line 362 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::ShiftRight CTBint i_beg,
CTBint i_end
[inline]
 

Shift range one position right.

The buffer elements in the range [i_beg...i_end] are shifted one element to the right, or higher indices, to occupy the range [i_beg+1...i_end+1].

The function uses the assignment operator for type T and assumes that element [i_end+1] is already constructed. It does not destruct element [i_beg], but its contents may have been grabbed. This element should be either destroyed or assigned to after this method returns.

The function is a noop if i_beg > i_end.

Definition at line 384 of file CTBrawBuffer.icc.

Referenced by CTBvector::Insert().

template<class T>
void CTBrawBuffer< T >::ShiftLeft CTBint i_beg,
CTBint i_end
[inline]
 

Shift range one position left.

The buffer elements in the range [i_beg...i_end] are shifted one element to the left, or lower indices, to occupy the range [i_beg-1...i_end-1].

The function uses the assignment operator for type T and assumes that element [i_beg-1] is already constructed. It does not destruct element [i_end], but its contents may have been grabbed. This element should be either destroyed or assigned to after this method returns.

The function is a noop if i_beg > i_end.

Definition at line 416 of file CTBrawBuffer.icc.

Referenced by CTBvector::Delete().

template<class T>
void CTBrawBuffer< T >::Copy CTBint i_beg,
CTBint i_size,
const T & rhs
[inline]
 

Copy scalar into rawbuffer.

The value of rhs is copied into i_size buffer elements starting at index i_beg using the assigment operator for type T. It is assumed that all these buffer elements are already constructed.

Definition at line 440 of file CTBrawBuffer.icc.

Referenced by CTBvector::operator=(), and CTBmatrix::operator=().

template<class T>
void CTBrawBuffer< T >::Copy CTBint i_beg,
CTBint i_size,
const T rhs[]
[inline]
 

Copy array into rawbuffer.

The first i_size elements of array rhs are i_size buffer elements starting at index i_beg using the assigment operator for type T. It is assumed that all these buffer elements are already constructed.

Definition at line 458 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::Dump int i_indent = 0,
ostream & os = cout,
const char * p_text = 0
const [inline]
 

Dump CTBrawBuffer object.

Definition at line 474 of file CTBrawBuffer.icc.

Referenced by CTBvector::Dump(), and CTBmatrix::Dump().

template<class T>
T * CTBrawBuffer< T >::operator+ CTBint i_ind [inline]
 

Calculate pointer to the i_ind 'th buffer element.

This operator allows to use a CTBrawBuffer object very much like a C array in index and pointer arithmetic. Expressions like

   CTBrawBuffer<int>  buf;
   ...
   int*   p1 = buf+3;
   int*   p2 = &buf[3];
are legal and in the example above, p1 and p2 will have identical values.

Note, that there is no operator-() . This is an intentional asymmetry because indices are always positive definite.

Definition at line 520 of file CTBrawBuffer.icc.

template<class T>
const T * CTBrawBuffer< T >::operator+ CTBint i_ind const [inline]
 

Calculate const pointer to the i_ind 'th buffer element.

Definition at line 529 of file CTBrawBuffer.icc.

template<class T>
T & CTBrawBuffer< T >::operator[] CTBint i_ind [inline]
 

Access buffer element.

A reference to the buffer element with index i_ind is returned. An access to this object is only defined if the element has been constructed before.

Definition at line 497 of file CTBrawBuffer.icc.

template<class T>
const T & CTBrawBuffer< T >::operator[] CTBint i_ind const [inline]
 

Constant access buffer element.

A reference to the buffer element with index i_ind is returned. An access to this object is only defined if the element has been constructed before.

Definition at line 542 of file CTBrawBuffer.icc.

template<class T>
bool CTBrawBuffer< T >::operator! const [inline]
 

Returns true if no buffer allocated (equivalent to Capacity() == 0).

Definition at line 551 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::operator T * [inline]
 

Convert to pointer to data.

Returns a pointer to the allocated buffer or 0 if the capacity is 0. Note, that the following tests are all equivalent:

    CTBrawBuffer<...>  buf;

    if (buf)
    if (buf.Capacity() > 0)
    if (!buf.Empty())
    if ((T*) buf)

Definition at line 573 of file CTBrawBuffer.icc.

template<class T>
CTBrawBuffer< T >::operator const T * const [inline]
 

Constant convert to pointer to data.

Returns a pointer to the allocated buffer or 0 if the capacity is 0.

Definition at line 585 of file CTBrawBuffer.icc.

template<class T>
void CTBrawBuffer< T >::DeleteBuffer [inline, private]
 

Release buffer memory.

Definition at line 594 of file CTBrawBuffer.icc.

Referenced by Resize(), and ~CTBrawBuffer().

template<class T>
void CTBrawBuffer< T >::CreateBuffer CTBint i_capacity [inline, private]
 

Create new buffer with capacity i_capacity.

Definition at line 608 of file CTBrawBuffer.icc.

Referenced by CTBrawBuffer(), and Resize().

template<class T>
CTBrawBuffer<T>& CTBrawBuffer< T >::operator= const CTBrawBuffer< T > & rhs [private]
 


Member Data Documentation

template<class T>
T* CTBrawBuffer::mp_data [private]
 

buffer area.

Definition at line 89 of file CTBrawBuffer.hxx.

template<class T>
CTBint CTBrawBuffer::mi_capacity [private]
 

capacity of buffer.

Definition at line 90 of file CTBrawBuffer.hxx.


The documentation for this class was generated from the following files:
Generated at Fri Oct 24 18:14:04 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001