KDynamicArray Class Template Reference

#include <kdynamicarray.h>

List of all members.


Detailed Description

template<typename VALUE_TYPE, typename ALLOCATOR = KBaseAllocator>
class KDynamicArray< VALUE_TYPE, ALLOCATOR >

Template class for dynamic array holding objects.
See also:
KStaticArray

Definition at line 55 of file kdynamicarray.h.


Public Types

typedef VALUE_TYPE  ValueType
  Type of the elements in the array.
typedef ALLOCATOR  AllocatorType
  Type of the class used for allocating memory.

Public Member Functions

  KDynamicArray ()
  Default constructor.
  KDynamicArray (size_t const pInitialSize)
  Constructor.
  KDynamicArray (KDynamicArray const &pArray)
  Copy constructor.
  ~KDynamicArray ()
  Destructor.
size_t  GetCapacity () const
  Gets the current capacity of the array.
size_t  GetSize () const
  Gets the size of the array.
void  Reserve (size_t const pCount)
  Assures that sufficient memory is allocated to hold n objects in the array, and increases the capacity if necessary.
void  PushBack (ValueType const &pValue, size_t const pNCopies=1)
  Appends n objects at the end of the array.
void  Insert (size_t const pIndex, ValueType const &pValue, size_t const pNCopies=1)
  Inserts n objects at the specified position.
void  PopBack (size_t pNElements=1)
  Removes n objects at the end.
void  Remove (size_t const pIndex, size_t pNElements=1)
  Removes n objects at the specified position.
ValueType operator[] (size_t const pIndex)
  Gets nth object in the array.
ValueType const &  operator[] (size_t const pIndex) const
  Gets nth object in the array.
KDynamicArray operator= (KDynamicArray const &pArray)
  Assignment operator.

Member Typedef Documentation

Type of the elements in the array.

Definition at line 59 of file kdynamicarray.h.

typedef ALLOCATOR AllocatorType

Type of the class used for allocating memory.

Definition at line 61 of file kdynamicarray.h.


Constructor & Destructor Documentation

KDynamicArray (  )  [inline]

Default constructor.

Definition at line 64 of file kdynamicarray.h.

KDynamicArray ( size_t const   pInitialSize  )  [inline]

Constructor.

Parameters:
pInitialSize  initial capacity of this array

Definition at line 75 of file kdynamicarray.h.

References Reserve().

KDynamicArray ( KDynamicArray< VALUE_TYPE, ALLOCATOR > const &  pArray  )  [inline]

Copy constructor.

Remarks:
The copy constructor of VALUE_TYPE will be invoked in order to copy the value of elements to the new array.

Definition at line 89 of file kdynamicarray.h.

References Reserve().

~KDynamicArray (  )  [inline]

Destructor.

Definition at line 101 of file kdynamicarray.h.


Member Function Documentation

size_t GetCapacity (  )  const [inline]

Gets the current capacity of the array.

Definition at line 113 of file kdynamicarray.h.

size_t GetSize (  )  const [inline]

Gets the size of the array.

Definition at line 119 of file kdynamicarray.h.

void Reserve ( size_t const   pCount  )  [inline]

Assures that sufficient memory is allocated to hold n objects in the array, and increases the capacity if necessary.

Parameters:
pCount  Number of objects to reserve

Definition at line 128 of file kdynamicarray.h.

Referenced by KDynamicArray(), operator=(), and PushBack().

void PushBack ( ValueType const &  pValue,
size_t const   pNCopies = 1  
) [inline]

Appends n objects at the end of the array.

Parameters:
pValue  object to append
pNCopies  number of copies to append

Definition at line 149 of file kdynamicarray.h.

References K_ASSERT, and Reserve().

Referenced by Insert().

void Insert ( size_t const   pIndex,
ValueType const &  pValue,
size_t const   pNCopies = 1  
) [inline]

Inserts n objects at the specified position.

Parameters:
pIndex  position index
pValue  object to insert
pNCopies  number of copies to append

Definition at line 176 of file kdynamicarray.h.

References K_ASSERT, and PushBack().

void PopBack ( size_t  pNElements = 1  )  [inline]

Removes n objects at the end.

Parameters:
pNElements  number of objects to remove

Definition at line 225 of file kdynamicarray.h.

References K_ASSERT.

Referenced by Remove().

void Remove ( size_t const   pIndex,
size_t  pNElements = 1  
) [inline]

Removes n objects at the specified position.

Parameters:
pIndex  position index
pNElements  number of objects to remove

Definition at line 242 of file kdynamicarray.h.

References K_ASSERT, and PopBack().

ValueType& operator[] ( size_t const   pIndex  )  [inline]

Gets nth object in the array.

Parameters:
pIndex  position index

Definition at line 269 of file kdynamicarray.h.

ValueType const& operator[] ( size_t const   pIndex  )  const [inline]

Gets nth object in the array.

Parameters:
pIndex  position index

Definition at line 277 of file kdynamicarray.h.

KDynamicArray& operator= ( KDynamicArray< VALUE_TYPE, ALLOCATOR > const &  pArray  )  [inline]

Assignment operator.

Remarks:
The copy constructor of VALUE_TYPE will be invoked in order to copy the value of elements to the new array.

Definition at line 287 of file kdynamicarray.h.

References Reserve().