University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

Vector Class Reference

#include <Vector.h>

Inheritance diagram for Vector:

Sequence Collection Object List of all members.

Detailed Description

Vector: an array of objects, in sequential order.

A Vector is a kind of Sequence that stores its elements in a single memory block. Vector is the more efficient kind Sequence to use if elements are randomly accessed by their index, or if elements are only added and removed from the back of the Vector. If elements are frequently inserted and removed at the front or in the middle, then a List should be used instead. A Vector is indexed from 0..n-1 where n is the size() of the Vector. The array used to store elements may expand to accommodate more elements.


Public Member Functions

 Vector ()
 Construct an empty Vector.

 Vector (Natural)
 Construct an empty Vector with a suggested capacity.

 Vector (CollectionID)
 Copy this Vector from another Collection.

virtual ~Vector ()
 Release a Vector. Deletes the array used for the storage of elements.

virtual ObjectID clone () const
 Clone a shallow copy of this Vector.

Natural size () const
 Return the size of this Vector.

virtual ObjectID last () const
 Return the last Object in this Vector.

virtual Void addLast (ObjectID)
 Add an Object to the back of this Vector.

virtual Void removeLast ()
 Remove an Object from the back of this Vector.

virtual ObjectID getAt (Integer) const
 Get the Object at an indexed position.

virtual Void putAt (Integer, ObjectID)
 Replace an Object at an indexed position.

virtual Void addAt (Integer, ObjectID)
 Insert an Object at an indexed position.

virtual Void removeAt (Integer)
 Remove an Object at an indexed position.


Constructor & Destructor Documentation

Vector::Vector  ) 
 

Construct an empty Vector.

Allocates an array of the default capacity, which may eventually expand if more capacity is later required. Use this constructor if the required capacity is unknown.

Returns:
an empty Vector.

Vector::Vector Natural  capacity  ) 
 

Construct an empty Vector with a suggested capacity.

Allocates an array of the specified capacity, which may eventually expand if more capacity is later required. Use this constructor if the required capacity is known.

Parameters:
capacity - the initial capacity for this Vector.
Returns:
a Vector of the suggested capacity.

Vector::Vector CollectionID  other  ) 
 

Copy this Vector from another Collection.

Allocates an array of sufficient capacity to store all the elements of the other Collection, then uses addAll() to include the other Collection. This Vector may eventually expand, if more capacity is later required.

Parameters:
other - the other Collection to copy.
Returns:
a Vector containing the elements of the Collection.

Vector::~Vector  )  [virtual]
 

Release a Vector. Deletes the array used for the storage of elements.


Member Function Documentation

Void Vector::addAt Integer  index,
ObjectID  object
[virtual]
 

Insert an Object at an indexed position.

All existing elements from the index position to the end of the Vector are moved up by one position and the new Object is inserted at the vacant index position. If the capacity of the Vector is exceeded, a larger memory block is allocated. This method copies object references, with a linear time penalty. To avoid this penalty when making frequent insertions, a List should be used instead. May raise an OutOfRange exception, if the index is out of bounds.

Parameters:
index - an index.
object - the Object to be inserted.

Reimplemented from Sequence.

Void Vector::addLast ObjectID  object  )  [virtual]
 

Add an Object to the back of this Vector.

More efficient implementation than the inherited version.

Parameters:
object - the Object to be added.

Reimplemented from Sequence.

ObjectID Vector::clone  )  const [virtual]
 

Clone a shallow copy of this Vector.

The resulting Vector manages a separate array for storage, but shares the Object elements of this Vector.

Returns:
a shallow copy of this Vector.

Reimplemented from Object.

ObjectID Vector::getAt Integer  index  )  const [virtual]
 

Get the Object at an indexed position.

May raise an OutOfRange exception if the index is out of bounds.

Parameters:
index - an index.
Returns:
the Object at this index.

Reimplemented from Sequence.

ObjectID Vector::last  )  const [virtual]
 

Return the last Object in this Vector.

More efficient implementation than the inherited version. May raise an OutOfRange execption, if the Vector is empty.

Returns:
the last Object in this Vector.

Reimplemented from Sequence.

Void Vector::putAt Integer  index,
ObjectID  object
[virtual]
 

Replace an Object at an indexed position.

May raise an OutOfRange exception if the index is out of bounds.

Parameters:
index - an index.
object - the Object to be stored at this index.

Reimplemented from Sequence.

Void Vector::removeAt Integer  index  )  [virtual]
 

Remove an Object at an indexed position.

All existing elements from the index+1 position to the end of the Vector are moved down by one position. The removed Object reference is overwritten. This method copies object references, with a linear time penalty. To avoid this penalty when making frequent removals, a List should be used instead. May raise an OutOfRange exception, if the index is out of bounds.

Parameters:
index - an Integer index.

Reimplemented from Sequence.

Void Vector::removeLast  )  [virtual]
 

Remove an Object from the back of this Vector.

More efficient implementation than the inherited version. May raise an OutOfRange execption, if the Vector is empty.

Reimplemented from Sequence.

Natural Vector::size  )  const [virtual]
 

Return the size of this Vector.

Counts the number of Object elements held in this Vector.

Returns:
the element count.

Reimplemented from Collection.


The documentation for this class was generated from the following files:
Generated on Fri May 5 17:17:20 2006 for The Simons Component Library by doxygen1.3