Magi

Contact info
Studies
  Scientific publications
  Master's thesis
Work
Software
Hobbies
Other Articles
  Evolution
  Metsola
  Pseudoart
Photography
Historical

© Marko Grönroos, 1998


class Array

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

Definition#include <pararr.h>
Template formArray<class TYPE>
InheritsObject
List of all Methods

Annotated List
Files
Globals
Hierarchy
Index

Public Members

Detailed Description

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 object.h.

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

int lower

Lower bound of the array. DO NOT MODIFY! This should be an access method, but is not.

int upper

Upper bound of the array. DO NOT MODIFY! This should be an access method, but is not.

int size

Size of the array. DO NOT MODIFY! This should be an access method, but is not.

Array (int siz=0)

Creates an array of the given size. 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.

Array (int low, int upp)

Creates an array with the given lower and upper bounds.

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

void make (int low, int upp)

Creates an array with the given lower and upper bounds. 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.

void make (int siz)

Creates an array of the given size. 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.

~Array ()
[virtual]

Destructor destroys all the objects contained by the Array.

void empty ()

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

void add (TYPE* i)

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.

void add (const TYPE& i)

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.

void put (TYPE* i, int loc)

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:
iThe object to be inserted.
locIndex of the insertion point.

void put (const TYPE& i, int loc)

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:
iThe object to be inserted.
locIndex of the insertion point.

void put (TYPE* p)

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.

const TYPE& operator[] (int loc)
[const]

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.

TYPE& operator[] (int loc)

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.

const TYPE* getp (int loc)
[const]

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.

TYPE* getp (int loc)

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.

int find (const TYPE& item)
[const]

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

void remove (int loc)

Destroys the object with the given index number from the array. Does not fill the hole, but leaves it NULL.

void removeFill (int loc)

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.

void cut (int loc)

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

void resize (int low, int upp)

Changes the bounds of the Array to the given ones. New size is calculated accordingly. Reserves or destructs as needed.

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

Standard =-operator. Performs deep copy.

>>
CArchive& operator>> (CArchive& arc)
[const]

Serialization support for the Array.

IStream& operator<< (IStream& arc)

Serialization support for the Array.

void check ()
[const virtual]

Implementation for Object. Checks the integrity of the Array.

void quicksort ()

Sorts the values in the Array.

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

Generated by: magi@magi.yok.utu.fi on Thu Sep 30 15:45:09 199.