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

lrt::Array Class Template Reference

The class template Array<T> implements a bounds-checked, constant-length array of values of type T. More...

#include <rtcollect.h>

Inheritance diagram for lrt::Array:

Inheritance graph
[legend]
List of all members.

Public Methods

 Array (int length)
 Creates an array of given length.

 Array (const Array< T > &)
 Copies the contents of the given array into this one.

 Array (const T *ptr, int off, int len)
 Creates an array by extracting data from the given C pointer. More...

virtual ~Array ()
 Destroys the array and all contained data.

int length () const
 Returns the array's length. More...

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 the array. More...

Array< T > & operator= (const Array< T > &)
 Copies the contents of the given array over to this one.

const T * getData () const
 Returns a C-style pointer to the array's data. More...

int indexOf (const T &elem, int pos=0) const
 Finds the first occurence of elem, starting from pos. More...

void exchange (int p1, int p2)
 Exchanges the elements at the given positions.

void sort ()
 Sorts the array using a quicksort algorithm and the default comparison function stdCompare.

void reverse ()
 Reverses the order of all the elements in the array.

void sort (int(*compareFun)(const T &, const T &), int l=0, int r=Math::MAX_INT)
 Sorts the array using a quicksort algorithm and a custom comparison function.


Protected Methods

int check (int)
 Checks if a given array index is valid. More...

int checkConst (int) const
 Checks if a given array index is valid. More...


Static Protected Methods

void copy (const Array< T > *source, int srcPos, Array< T > *dest, int destPos, int length)
 Copies some data between arrays very fastly.


Protected Attributes

int len
 The array's length.

T * data
 The array's data.


Detailed Description

template<class T>
class lrt::Array< T >

The class template Array<T> implements a bounds-checked, constant-length array of values of type T.

Methods for access to elements are provided.


Constructor & Destructor Documentation

template<class T>
lrt::Array< T >::Array (  const T *    ptr,
int    off,
int    len
) 
 

Creates an array by extracting data from the given C pointer.

You are responsible yourself for checking the validity of the pointer, off and len!


Member Function Documentation

template<class T>
int lrt::Array< T >::check (  int    )  [inline, protected]
 

Checks if a given array index is valid.

If not, exits the application. This method should be used to check accesses which may modify the array.

Reimplemented in lrt::Vector.

template<class T>
int lrt::Array< T >::checkConst (  int    )  const [inline, protected]
 

Checks if a given array index is valid.

If not, exits the application. This method should be used to check accesses which may not modify the array.

template<class T>
const T * lrt::Array< T >::getData (    )  const [inline]
 

Returns a C-style pointer to the array's data.

The data cannot be modified through this pointer, but changes made to the array using the [] operators will be visible by it. This implies that should only use the pointer for a short time, e.g. to call some system C functions with it.

template<class T>
int lrt::Array< T >::indexOf (  const T &    elem,
int    pos = 0
)  const
 

Finds the first occurence of elem, starting from pos.

Note that an operator==(T &, T &) must be defined. If elem is not found, returns -1.

template<class T>
int lrt::Array< T >::length (    )  const [inline]
 

Returns the array's length.

For Array<T> objects, the value will be constant during their lifetime.

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

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

This method is used for changing the element. If index is negative or larger than the array's size, the program will be closed.

Reimplemented in lrt::Vector.

template<class T>
const T & lrt::Array< 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 in lrt::Vector.


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