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

Array Class Template Reference

Generic array template, for objects and non-objects. More...

#include <mpararr.h>

Inheritance diagram for Array:

List of all members.

Public Methods

 Array (int siz=0)
void make (int siz)
void isRef (bool isref)
virtual ~Array ()
void empty ()
void add (TYPE *i)
void add (const TYPE &i)
void put (TYPE *i, int loc)
void put (const TYPE &i, int loc)
void put (TYPE *p)
const TYPE & operator[] (int loc) const
TYPE & operator[] (int loc)
const TYPE * getp (int loc) const
TYPE * getp (int loc)
int find (const TYPE &item) const
void remove (int loc)
void removeFill (int loc)
void cut (int loc)
void resize (int newsize)
void operator= (const Array< TYPE > &other)
virtual void check () const
void quicksort ()
int size () const

Detailed Description

template<class TYPE>
class Array< TYPE >

Generic array template, for objects and non-objects.

Much better than manys other implementations.

Arrays can contain empty slots that do not point to an existing object. Some methods can also return NULL references to objects, which is rather special behaviour for C++ references. You can check the nullness of an object by the isnull(const Object&)-function in mobject.h.

if (isnull(myArray[5])) {...}

Definition at line 53 of file mpararr.h.


Constructor & Destructor Documentation

Array int    siz = 0 [inline]
 

Creates an array of the given size with lower bound 0.

If no size is given, creates an empty array.

NOTE: The objects are not created with this constructor, but only when they are accessed first time.

Definition at line 66 of file mpararr.h.

virtual ~Array   [inline, virtual]
 

Destructor destroys all the objects contained by the Array.

Definition at line 113 of file mpararr.h.


Member Function Documentation

void add const TYPE &    i [inline]
 

Adds the given object to the end of the array; increments the size of the array by one.

NOTE: Does not takes the ownership of the object, but just copies it using the copy constructor.

Definition at line 148 of file mpararr.h.

void add TYPE *    i [inline]
 

Adds the given object to the end of the array; increments the size of the array by one.

NOTE: Takes the ownership of the object.

Definition at line 136 of file mpararr.h.

Referenced by Array< Thread >::put().

virtual void check   const [inline, virtual]
 

Implementation for Object.

Checks the integrity of the Array.

Definition at line 374 of file mpararr.h.

void cut int    loc [inline]
 

Removes the object with the given index from the Array, but does NOT destruct the object; just removes the reference to it.

Definition at line 306 of file mpararr.h.

void empty   [inline]
 

Destroys all the objects in the Array, but does NOT change the size.

Definition at line 122 of file mpararr.h.

Referenced by copyClone(), Array< Thread >::make(), Array< Thread >::operator=(), and Array< Thread >::~Array().

int find const TYPE &    item const [inline]
 

Finds the given object in the Array and returns it's index number, or -1 if not found.

Definition at line 272 of file mpararr.h.

TYPE* getp int    loc [inline]
 

Returns a pointer to the loc:th item in the Array.

If the item does not exist, a NULL is returned.

Throws 'assertion_failed' if the index is out of bounds.

Non-const version.

Definition at line 264 of file mpararr.h.

const TYPE* getp int    loc const [inline]
 

Returns a pointer to the loc:th item in the Array.

If the item does not exist, a NULL is returned.

Throws 'assertion_failed' if the index is out of bounds.

Const version.

Definition at line 252 of file mpararr.h.

Referenced by copyClone().

void isRef bool    isref [inline]
 

Sets a flag that tells whether is not the objects inserted in this array are owned by the array or not.

Thus, with value 'true', the class does not delete the objects, while with 'false' it does.

The default for Array is 'false' (it owns the objects).

NOTE: This feature entirely replaces the RefArray class.

Definition at line 109 of file mpararr.h.

void make int    siz [inline]
 

Creates an array of the given size with lower bound 0.

If the array previously has any content, that content is destroyed.

NOTE: The objects are not created with this method, but only when they are accessed first time.

Definition at line 86 of file mpararr.h.

Referenced by Array< Thread >::Array(), copyClone(), and Array< Thread >::operator=().

void operator= const Array< TYPE > &    other [inline]
 

Standard =-operator.

Performs deep copy.

Definition at line 337 of file mpararr.h.

TYPE& operator[] int    loc [inline]
 

Returns a reference to the loc:th item in the Array.

If the item does not exist (is null), it is created.

Throws 'assertion_failed' if the index is out of bounds.

Non-const version.

Definition at line 235 of file mpararr.h.

const TYPE& operator[] int    loc const [inline]
 

Returns a reference to the loc:th item in the Array.

If the item does not exist (is null), it is created.

Throws 'assertion_failed' if the index is out of bounds.

Const version.

Definition at line 218 of file mpararr.h.

void put TYPE *    p [inline]
 

Adds the given object to any NULL location in the array; if no null locations exists, the object is added to the end of the array just like in add.

NOTE: Takes the ownership of the object.

Definition at line 202 of file mpararr.h.

void put const TYPE &    i,
int    loc
[inline]
 

Puts the given object to the given location.

Old item in the same index location is destroyed.

NOTE: Does not takes the ownership of the object, but just copies it using the copy constructor.

Parameters:
i  The object to be inserted.
loc  Index of the insertion point.

Definition at line 184 of file mpararr.h.

void put TYPE *    i,
int    loc
[inline]
 

Puts the given object to the given location.

Old item in the same index location is destroyed.

NOTE: Takes the ownership of the object.

Parameters:
i  The object to be inserted.
loc  Index of the insertion point.

Definition at line 165 of file mpararr.h.

Referenced by copyClone(), and Array< Thread >::operator=().

void quicksort   [inline]
 

Sorts the values in the Array.

NOTE: The contained objects MUST inherit Comparable, and be of the same class!

Definition at line 383 of file mpararr.h.

void remove int    loc [inline]
 

Destroys the object with the given index number from the array.

Does not fill the hole, but leaves it NULL.

Definition at line 282 of file mpararr.h.

void removeFill int    loc [inline]
 

Destroys the object with the given index number from the Array, and fills the hole by shifting the rest of the items one index downwards.

Definition at line 293 of file mpararr.h.

void resize int    newsize [inline]
 

Changes the bounds of the Array to the given ones.

New size is calculated accordingly. Reserves or destructs as needed.

Definition at line 314 of file mpararr.h.

Referenced by Array< Thread >::add(), Array< Thread >::put(), and Array< Thread >::removeFill().

int size   const [inline]
 

Returns number of elements (or null elements) in array.

Definition at line 388 of file mpararr.h.

Referenced by clone(), copyClone(), and Turtle::drawLSystem().


The documentation for this class was generated from the following file:
Generated on Thu Feb 10 20:06:43 2005 for LibMagiC by doxygen1.2.18