Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

lrt::Vector Class Template Reference

The class template Vector<T> implements a growable array of components of type T. More...

#include <rtcollect.h>

Inheritance diagram for lrt::Vector:

Inheritance graph
[legend]
List of all members.

Public Methods

 Vector (int length=0)
 Creates a growable array of given initial length.

 Vector (const Vector< T > &)
 Creates a new growable array by copying the elements of the given array over.

const T & operator[] (int index) const
 Returns a reference to the index'th element of the array. More...

T & operator[] (int index)
 Returns a reference to the index'th element of this array through which the element can be changed. More...

Vector< T > & operator= (const Vector< T > &)
 Copies the data from another array over to this one.

int check (int)
 Checks an array index for validity. More...

Vector< T > & operator+= (const T &)
 Appends an element to this array. More...

Vector< T > & operator+= (const Array< T > &)
 Appends all the elements from another array to this one. More...

void insert (T elem, int before)
 Inserts an element before the given index. More...

void remove (int pos)
 Removes the element at index pos. More...

void remove (int start, int length)
 Removes all elements between indexes start and (not including) start + length.

void clear ()
 Removes all elements.


Protected Methods

int up2pow (int val)
 Returns the smallest power of two (but at least 16) which is equal or larger than val. More...


Static Protected Methods

void copy (const Array< T > *source, int srcPos, Vector< T > *dest, int destPos, int length)
 Copies some data over to a vector. More...


Protected Attributes

int capacity
 The internal allocated memory size.


Detailed Description

template<class T>
class lrt::Vector< T >

The class template Vector<T> implements a growable array of components of type T.

If there is enough memory available, setting an element with positive index will never fail using this class, but resize the array instead so that it becomes large enough to hold the given number of elements. Elements can also easily be appended to the array (this method should be reasonably fast). Some methods are provided to insert or remove elements from the middle of the array, but these are slow.


Member Function Documentation

template<class T>
int lrt::Vector< T >::check (  int    ) 
 

Checks an array index for validity.

If the index is too large, the array is resized appropriately.

Reimplemented from lrt::Array.

template<class T>
void lrt::Vector< T >::copy (  const Array< T > *    source,
int    srcPos,
Vector< T > *    dest,
int    destPos,
int    length
)  [static, protected]
 

Copies some data over to a vector.

If the vector is not large enough to hold the data, it is first resized.

template<class T>
void lrt::Vector< T >::insert (  T    elem,
int    before
) 
 

Inserts an element before the given index.

Since this method moves around all elements after before, it may be quite slow.

template<class T>
Vector< T > & lrt::Vector< T >::operator+= (  const Array< T > &    ) 
 

Appends all the elements from another array to this one.

Most times, this method should be quite fast.

template<class T>
Vector< T > & lrt::Vector< T >::operator+= (  const T &    ) 
 

Appends an element to this array.

Most times, this method should be quite fast.

template<class T>
T & lrt::Vector< T >::operator[] (  int    index )  [inline]
 

Returns a reference to the index'th element of this array through which the element can be changed.

If the array is not yet large enough to store index elements, it is first resized appropriately.

Note: Be careful when exporting references to Vectors! If you add more elements to the vector after exporting the reference, the vector's data may become relocated and the reference may become invalid.

Reimplemented from lrt::Array.

template<class T>
const T & lrt::Vector< T >::operator[] (  int    index )  const [inline]
 

Returns a reference to the index'th element of the array.

If index is negative or larger than the array's size, the program will be closed.

Reimplemented from lrt::Array.

template<class T>
void lrt::Vector< T >::remove (  int    pos ) 
 

Removes the element at index pos.

Since this method moves around all elements after pos, it may be quite slow.

template<class T>
int lrt::Vector< T >::up2pow (  int    val )  [inline, protected]
 

Returns the smallest power of two (but at least 16) which is equal or larger than val.

This method is used to grow the array exponentially.


The documentation for this class was generated from the following files:
This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer