PUMA Library Reference Manual
Puma::Array< Item > Class Template Reference

#include <Puma/Array.h>

+ Inheritance diagram for Puma::Array< Item >:

Description

template<class Item>
class Puma::Array< Item >

Variable length array implementation. Grows with an increasing increment.

Template Parameters
ItemThe array item type.

Public Member Functions

 Array (long is=default_init_size, long incr=default_increment)
 Constructor. More...
 
 Array (const Array< Item > &array)
 Copy-constructor. More...
 
Array< Item > & operator= (const Array< Item > &copy)
 Assignment operator. More...
 
 ~Array ()
 Destructor. More...
 
void append (const Item &item)
 Append an item to the array. More...
 
void insert (long index, const Item &item)
 Insert an item at the given array index. More...
 
void prepend (const Item &item)
 Prepend an item. More...
 
void remove (long index)
 Remove the array item at the given array index. More...
 
void reset ()
 Reset the array. More...
 
Item & get (long index)
 Get a reference to the array item at the given array index. More...
 
Item & operator[] (long index)
 Get a reference to the array item at the given array index. More...
 
Item fetch (long index) const
 Get the array item at the given array index. More...
 
Item & lookup (long index) const
 Get a reference to the array item at the given array index. More...
 
long length () const
 Get the number of items in the array. More...
 
template<>
void reset ()
 

Static Protected Attributes

static const long default_init_size = 5
 Default array size. More...
 
static const long default_increment = 5
 Default array size increment. More...
 

Constructor & Destructor Documentation

◆ Array() [1/2]

template<class Item >
Puma::Array< Item >::Array ( long  is = default_init_size,
long  incr = default_increment 
)
inline

Constructor.

Parameters
isThe default size of the array.
incrThe default increment value.

◆ Array() [2/2]

template<class Item>
Puma::Array< Item >::Array ( const Array< Item > &  array)
inline

Copy-constructor.

Parameters
arrayThe array to copy.

◆ ~Array()

template<class Item >
Puma::Array< Item >::~Array ( )
inline

Destructor.

Destroys the array.

Member Function Documentation

◆ append()

template<class Item>
void Puma::Array< Item >::append ( const Item &  item)
inline

Append an item to the array.

Parameters
itemThe item to append.

◆ fetch()

template<class Item >
Item Puma::Array< Item >::fetch ( long  index) const
inline

Get the array item at the given array index.

Does not return a reference, thus the item may be implicitely copied.

Warning
Does not validate the index!
Parameters
indexThe array index.
Returns
The n-th array item.

◆ get()

template<class Item >
Item & Puma::Array< Item >::get ( long  index)
inline

Get a reference to the array item at the given array index.

If the index exceeds the array bounds, then the array is reallocated accordingly.

Parameters
indexThe array index.
Returns
A reference to the n-th array item.

◆ insert()

template<class Item>
void Puma::Array< Item >::insert ( long  index,
const Item &  item 
)
inline

Insert an item at the given array index.

Parameters
indexThe array index.
itemThe item to insert.

◆ length()

template<class Item >
long Puma::Array< Item >::length ( ) const
inline

Get the number of items in the array.

Returns
The length of the array.

◆ lookup()

template<class Item >
Item & Puma::Array< Item >::lookup ( long  index) const
inline

Get a reference to the array item at the given array index.

Warning
Does not validate the index!
Parameters
indexThe array index.
Returns
A reference to the n-th array item.

◆ operator=()

template<class Item>
Array< Item > & Puma::Array< Item >::operator= ( const Array< Item > &  copy)
inline

Assignment operator.

Parameters
copyThe array to copy.

◆ operator[]()

template<class Item >
Item & Puma::Array< Item >::operator[] ( long  index)
inline

Get a reference to the array item at the given array index.

If the index exceeds the array bounds, then the array is reallocated accordingly.

Parameters
indexThe array index.
Returns
A reference to the n-th array item.

◆ prepend()

template<class Item>
void Puma::Array< Item >::prepend ( const Item &  item)
inline

Prepend an item.

Parameters
itemThe item to prepend.

◆ remove()

template<class Item >
void Puma::Array< Item >::remove ( long  index)
inline

Remove the array item at the given array index.

Parameters
indexThe array index.

◆ reset() [1/2]

template<class Item >
void Puma::Array< Item >::reset ( )
inline

Reset the array.

Destroys the current array.

◆ reset() [2/2]

template<>
void Puma::Array< int >::reset ( )
inline

Member Data Documentation

◆ default_increment

template<class Item>
const long Puma::Array< Item >::default_increment = 5
staticprotected

Default array size increment.

◆ default_init_size

template<class Item>
const long Puma::Array< Item >::default_init_size = 5
staticprotected

Default array size.