PUMA Library Reference Manual
Loading...
Searching...
No Matches
Puma::Array< Item > Class Template Reference

#include <Puma/Array.h>

Inherited by Puma::PtrStack< CTree > [private], Puma::PtrStack< CObjectInfo > [private], Puma::PtrStack< Puma::CStructure > [private], Puma::Stack< bool > [private], Puma::Stack< const char * > [private], Puma::Stack< CProtection::Type > [private], Puma::Stack< Puma::Syntax::State > [private], Puma::Stack< Puma::CTree * > [private], Puma::Stack< MemberAccessOperator > [private], Puma::Stack< unsigned > [private], and Puma::Stack< Item > [private].

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

Static Protected Attributes

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

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]

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.