Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

CB2::Array< Tmemb > Class Template Reference

Multipurpose dynamic array. More...

#include <utils.h>

Inheritance diagram for CB2::Array< Tmemb >:

CB2::Class List of all members.

Public Types

typedef Array< Tmemb > this_type
 Template type alias.

typedef size_t size_type
 Size type.

typedef Tmemb * ref_type
 Item reference type.

typedef Iterator< this_type,
ref_type, Tmemb > 
iterator
 Iterator.

typedef RevIterator< this_type,
ref_type, Tmemb > 
rev_iterator
 Reverse iterator.


Public Member Functions

 Array (const size_type fragment=4096)
 Default constructor.

 Array (const this_type &prev)
 Copy constructor.

 ~Array ()
 Desctructor.

const this_typeoperator= (const this_type &prev)
 Copy assignment.

 operator const Tmemb * () const
 Implicit conversion operator.

const this_typeoperator<< (const Tmemb &prev)
 Append item at the end.

const this_typeoperator>> (const Tmemb &prev)
 Append item at the beginning.

const this_typeoperator+= (const size_type nmemb)
 Enlarge array by a number of items.

const this_typeoperator-= (const size_type nmemb)
 Shrink array by a number of items.

Tmemb & operator[] (const size_type pos) const
 Get item reference.

void Fill (const Tmemb *buffer, const size_type nmemb)
 Copy items from C-style array.

void Discart (const bool shrink=false)
 Discart the array.

size_type Len () const
 Return number of items.

bool Empty () const
 Check array for empty.

ref_type RefBegin () const
 Get starting reference.

ref_type RefEnd () const
 Get final reference.

ref_type RevRefBegin () const
 Get starting reverse reference.

ref_type RevRefEnd () const
 Get final reverse reference.

ref_type RefNext (const ref_type &prev) const
 Get succeding reference.

ref_type RefPrev (const ref_type &prev) const
 Get predecessing reference.

const Tmemb & Deref (const ref_type &ref) const
 Dereference.

const Tmemb & RevDeref (const ref_type &ref) const
 TODO.

iterator Begin () const
 Get starting iterator.

iterator End () const
 Get final iterator.

rev_iterator RevBegin () const
 Get starting reverse iterator.

rev_iterator RevEnd () const
 Get final reverse iterator.

void Cut (const size_type pos, const size_type cnt)
 Cut out piece of array.

void Insert (const size_type pos, const size_type cnt, const this_type &ins)
 Insert items.


Public Attributes

int tag
 Tag for user-specific data.


Private Member Functions

void allocate (const size_type nlen)
 Allocate memory for items.

void privatize (const this_type &prev)
 Copy data from another array.


Private Attributes

Tmemb * data
 Data storage.

size_type allocated
 Allocated memory space.

size_type len
 Members used.

size_type frag
 Fragment size.


Detailed Description

template<class Tmemb>
class CB2::Array< Tmemb >

Multipurpose dynamic array.

Multipurpose array type for storing values of the same kind. Grows in fragments, never shrinks by inself (shrinks only explicitly on Discart(true) method).

Note: This is a low-level array class, the elements are stored and copied bit-by-bit (no copy constructors or class assignments are called). Use List for storing class objects.

NB: As a low-level storage implementation, many operations have strict limitations on self-reference (i.e. you shouldn't insert values referenced from the same array instance). Use List for more robust (but slower) implementation.


Member Typedef Documentation

template<class Tmemb>
typedef Iterator< this_type, ref_type, Tmemb> CB2::Array< Tmemb >::iterator
 

Iterator.

template<class Tmemb>
typedef Tmemb* CB2::Array< Tmemb >::ref_type
 

Item reference type.

template<class Tmemb>
typedef RevIterator< this_type, ref_type, Tmemb> CB2::Array< Tmemb >::rev_iterator
 

Reverse iterator.

template<class Tmemb>
typedef size_t CB2::Array< Tmemb >::size_type
 

Size type.

template<class Tmemb>
typedef Array< Tmemb> CB2::Array< Tmemb >::this_type
 

Template type alias.


Constructor & Destructor Documentation

template<class Tmemb>
CB2::Array< Tmemb >::Array const size_type  fragment = 4096  )  [inline]
 

Default constructor.

Create empty array.

Parameters:
fragment Default fragment size (in items count).

template<class Tmemb>
CB2::Array< Tmemb >::Array const this_type prev  )  [inline]
 

Copy constructor.

Copy array items from another array (copy is bit-by-bit).

Parameters:
prev Array to copy.

template<class Tmemb>
CB2::Array< Tmemb >::~Array  )  [inline]
 

Desctructor.

Dispose the memory of the array.


Member Function Documentation

template<class Tmemb>
void CB2::Array< Tmemb >::allocate const size_type  nlen  )  [inline, private]
 

Allocate memory for items.

Allocate or reallocate memory for items.

The memory is rounded to nearest fragment. If the new count of items is lower then the original count, the memory pool is untouched.

If the allocation/reallocation fails, ExceptionMemory is thrown.

Parameters:
nlen Number of items.

template<class Tmemb>
iterator CB2::Array< Tmemb >::Begin  )  const [inline]
 

Get starting iterator.

Returns:
Starting iterator.

template<class Tmemb>
void CB2::Array< Tmemb >::Cut const size_type  pos,
const size_type  cnt
[inline]
 

Cut out piece of array.

Remove several items from the array. The items are defined by the position of the first removed item and count of items that follows (and should be removed).

If 'pos' or 'cnt' is out of range, ExceptionRange is thrown.

Parameters:
pos Index of the first item to remove.
cnt Number of items to remove.

template<class Tmemb>
const Tmemb& CB2::Array< Tmemb >::Deref const ref_type ref  )  const [inline]
 

Dereference.

Get the item value referenced by 'ref'. If the reference is out of range, ExceptionMemory is thrown.

Parameters:
ref Item reference.
Returns:
Item value.

template<class Tmemb>
void CB2::Array< Tmemb >::Discart const bool  shrink = false  )  [inline]
 

Discart the array.

Discart the contents of the array.

Parameters:
shrink Whether the memory should be disposed.

template<class Tmemb>
bool CB2::Array< Tmemb >::Empty  )  const [inline]
 

Check array for empty.

Returns:
True if the array is empty.

template<class Tmemb>
iterator CB2::Array< Tmemb >::End  )  const [inline]
 

Get final iterator.

Returns:
Final iterator.

template<class Tmemb>
void CB2::Array< Tmemb >::Fill const Tmemb *  buffer,
const size_type  nmemb
[inline]
 

Copy items from C-style array.

Copy items from a standard C-style array. Members are copied bit-by-bit.

Original contents of the array is discarted.

Parameters:
buffer Array with members to copy.
nmemb Number of members to copy.

template<class Tmemb>
void CB2::Array< Tmemb >::Insert const size_type  pos,
const size_type  cnt,
const this_type ins
[inline]
 

Insert items.

Insert items from another array into this array. The first item from 'ins' is inserted at index 'pos' and totally 'cnt' items are inserted (previous items on these positions are shifted back).

If 'pos' or 'cnt' is out of range, ExceptionRange is thrown.

NB: This method doesn't support self-reference. If 'ins' is this same array, ExceptionAssert is thrown.

Parameters:
pos Index of the first inserted item.
cnt Number of items to insert.
ins Array of items to insert.

template<class Tmemb>
size_type CB2::Array< Tmemb >::Len  )  const [inline]
 

Return number of items.

Returns:
Number of items in the array.

template<class Tmemb>
CB2::Array< Tmemb >::operator const Tmemb *  )  const [inline]
 

Implicit conversion operator.

Returns constant pointer to the array.

Returns:
Constant pointer.

template<class Tmemb>
const this_type& CB2::Array< Tmemb >::operator+= const size_type  nmemb  )  [inline]
 

Enlarge array by a number of items.

Enlarge the array by allocating memory for 'nmemb' items at the end. The contents of the items is undefined.

Parameters:
nmemb Number of items to allocate.
Returns:
Reference to this.

template<class Tmemb>
const this_type& CB2::Array< Tmemb >::operator-= const size_type  nmemb  )  [inline]
 

Shrink array by a number of items.

Shrink the array by disposing 'nmemb' items at the end. If a larger count of items than the length of the array is specified, the array made empty.

Parameters:
nmemb Number of items to dispose.
Returns:
Reference to this.

template<class Tmemb>
const this_type& CB2::Array< Tmemb >::operator<< const Tmemb &  prev  )  [inline]
 

Append item at the end.

Append one item at the end of the array.

Parameters:
prev Member to append.
Returns:
Reference to this.

template<class Tmemb>
const this_type& CB2::Array< Tmemb >::operator= const this_type prev  )  [inline]
 

Copy assignment.

Copy array items from another array (copy is bit-by-bit).

Parameters:
prev Array to copy.

template<class Tmemb>
const this_type& CB2::Array< Tmemb >::operator>> const Tmemb &  prev  )  [inline]
 

Append item at the beginning.

Append item at the beginning of the array.

Note: The appended item should not be a reference to another item from this array (in this case a wrong item will be appended).

Parameters:
prev Item to append.
Returns:
Reference to this.

template<class Tmemb>
Tmemb& CB2::Array< Tmemb >::operator[] const size_type  pos  )  const [inline]
 

Get item reference.

Get reference to an item from the array indexed by 'pos'. If 'pos' is out of range, ExceptionRange is thrown.

Parameters:
pos Index of the member.
Returns:
Reference to a member.

template<class Tmemb>
void CB2::Array< Tmemb >::privatize const this_type prev  )  [inline, private]
 

Copy data from another array.

Copy data from another array, unless this is self-reference.

Parameters:
prev Array to copy from.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RefBegin  )  const [inline]
 

Get starting reference.

Get the reference to the first item in the array as a pointer to the first item (or NULL on empty array).

Returns:
Starting reference.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RefEnd  )  const [inline]
 

Get final reference.

Get the final reference as the pointer to the memory position after the last item in the array (or NULL on empty array).

Returns:
Final reference.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RefNext const ref_type prev  )  const [inline]
 

Get succeding reference.

Get the reference to an item succeding the item referenced by 'prev' (i.e. increase the pointer by one item). If the pointer is final or invalid, final reference is returned).

Parameters:
prev Original reference.
Returns:
Next reference.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RefPrev const ref_type prev  )  const [inline]
 

Get predecessing reference.

Get the reference to an item predecessing the item referenced by 'prev' (i.e. decrease the pointer by one item). If the pointer is final or invalid, final reference is returned).

Parameters:
prev Original reference.
Returns:
Previous reference.

template<class Tmemb>
rev_iterator CB2::Array< Tmemb >::RevBegin  )  const [inline]
 

Get starting reverse iterator.

Returns:
Starting reverse iterator.

template<class Tmemb>
const Tmemb& CB2::Array< Tmemb >::RevDeref const ref_type ref  )  const [inline]
 

TODO.

template<class Tmemb>
rev_iterator CB2::Array< Tmemb >::RevEnd  )  const [inline]
 

Get final reverse iterator.

Returns:
Final reverse iterator.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RevRefBegin  )  const [inline]
 

Get starting reverse reference.

Get the reference to the last item in the array as a pointer RefEnd().

Returns:
Starting reverse reference.

template<class Tmemb>
ref_type CB2::Array< Tmemb >::RevRefEnd  )  const [inline]
 

Get final reverse reference.

Get the final reverse reference, which is equivaltent to the starting forward reference.

Returns:
Final reference.


Member Data Documentation

template<class Tmemb>
size_type CB2::Array< Tmemb >::allocated [private]
 

Allocated memory space.

template<class Tmemb>
Tmemb* CB2::Array< Tmemb >::data [private]
 

Data storage.

template<class Tmemb>
size_type CB2::Array< Tmemb >::frag [private]
 

Fragment size.

template<class Tmemb>
size_type CB2::Array< Tmemb >::len [private]
 

Members used.

int CB2::Class::tag [inherited]
 

Tag for user-specific data.


The documentation for this class was generated from the following file:
Generated on Thu Sep 16 23:26:49 2004 for ColorBox2 by doxygen 1.3.7