Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Array Class Template Reference

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

#include <mpararr.h>

Inheritance diagram for Array::

Object 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 ()
iterator start () const

Public Attributes

int size

Detailed Description

template<class TYPE> class Array

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 52 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.

~Array ( ) [inline, virtual]
 

Destructor destroys all the objects contained by the Array.

Definition at line 106 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 141 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 129 of file mpararr.h.

Referenced by put().

void check ( ) const [inline, virtual]
 

Implementation for Object.

Checks the integrity of the Array.

Reimplemented from Object.

Definition at line 367 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 299 of file mpararr.h.

void empty ( ) [inline]
 

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

Definition at line 115 of file mpararr.h.

Referenced by make(), operator=(), MagiC::String::split(), and ~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 265 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 257 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 245 of file mpararr.h.

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 102 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 79 of file mpararr.h.

Referenced by Array(), and operator=().

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

Standard =-operator.

Performs deep copy.

Definition at line 330 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 228 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 211 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 195 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 177 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 158 of file mpararr.h.

Referenced by operator=(), and MagiC::String::split().

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 376 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 275 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 286 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 307 of file mpararr.h.

Referenced by add(), put(), and removeFill().


Member Data Documentation

int size
 

Size of the array.

DO NOT MODIFY! This should be an access method, but is not.

Definition at line 58 of file mpararr.h.


The documentation for this class was generated from the following file:
Generated at Tue Dec 4 19:53:28 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001