WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_2.html taken on Sat Jun 10 19:13:31 1995

Go to the previous, next section.

ArrayOb--Array of Object Pointers

SYNOPSIS

#include <nihcl/ArrayOb.h>

BASE CLASS

Collection

DERIVED CLASSES

None

RELATED CLASSES

Iterator

DESCRIPTION

Class ArrayOb provides a basic, one dimensional array of pointers to objects (type Object*). You can subscript ArrayOb objects much like ordinary C arrays, but unlike C arrays, you can change the size of an ArrayOb at execution time, the array elements can be pointers to instances of a variety of NIH Library classes (not just a single type as in C), and you can perform some operations, such as assign, compare, and print, on the entire array instead of just individual elements.

CONSTRUCTORS

ArrayOb(unsigned capacity =DEFAULT_CAPACITY)
Constructs an instance of an ArrayOb with a capacity of capacity characters. The array is initialized with pointers to the nil object. An NIHCL_ALLOCSIZE error is raised if capacity is not greater than 0.

ArrayOb(const ArrayOb& a)
Constructs an instance of an ArrayOb that is the same size as ArrayOb a and initializes it to point to the same objects contained in a.

ADDING OBJECTS

virtual Collection& addContentsTo(Collection& cltn) const
Adds the objects in this ArrayOb to the Collection cltn.

REMOVING OBJECTS

virtual void removeAll()
Removes all the object pointers from this ArrayOb and replaces them with pointers to the nil object.

SEARCHING

virtual unsigned hash() const
Returns a number that classes such as Set can use as a hash table probe. Class ArrayOb implements hash() by exclusive ORing the results of applying hash() to all objects in an ArrayOb.

RELATIONAL OPERATORS

bool operator==(const ArrayOb&) const
bool operator!=(const ArrayOb&) const
Returns YES if the left ArrayOb operand is equal to (or not equal to) the right ArrayOb operand.

COMPARING ARRAYOBS

virtual int compare(const Object& a) const
Does a lexical comparison of this ArrayOb and the argument object a and returns a negative result if this ArrayOb is less than a, zero if they are equal, and a positive result if this ArrayOb is greater than a. The argument object must return the address of the ArrayOb class descriptor as its species() for it to be considered a comparable class. The compare() function compares the individual objects in the arrays by applying compare() to them.

TESTING ARRAYOBS

virtual bool isEqual(const Object& a) const
Returns YES if this ArrayOb and the argument object are comparable and they have equal values. The argument object a is comparable if it returns the address of class ArrayOb's class descriptor for its species(). Class ArrayOb implements isEqual() by applying isEqual() to all objects in an ArrayOb.

COPYING ARRAYOBS

void operator=(const ArrayOb&)
Replaces the left ArrayOb operand with a copy of the right ArrayOb operand. Only the pointers to the objects contained in the right operand are copied, not the objects they point to.

virtual void deepenShallowCopy()
Converts this shallow copy to a deep copy by applying deepCopy() to all the object pointers, replacing each pointer with a pointer to its copy.

INDEXING ARRAYOBS

Object*& elem(int i)
const Object *const& elem(int i) const
Object*& operator[](int i)
const Object *const& operator[](int i) const
virtual Object*& at(int i)
virtual const Object *const& at(int i) const
Returns a reference to the pointer to the ith object in this ArrayOb. Zero-origin index is used--characters are indexed from 0 to size()-1. The operator[] and at() functions perform a range check on the index i and raise an NIHCL_INDEXRANGE error if i is out of bounds. The elem() functions do not perform a range check.

ARRAYOB CAPACITY AND SIZE

virtual unsigned capacity() const
virtual unsigned size() const
Returns the number of object pointers in this ArrayOb.

virtual void reSize(unsigned newSize)
Changes the capacity (size) of this Arraychar to newSize object pointers, which must be greater than 0. If the capacity is increased, the additional object pointers are initialized to point to the nil object.

SUPPORT FOR ITERATORS

virtual Object* doNext(Iterator& pos) const
Returns a pointer to the next object in this ArrayOb, or 0 if no more objects remain. The Iterator argument pos maintains the current position in the ArrayOb.

SORTING ARRAYOBS

virtual void sort()
Sorts the objects in this ArrayOb into ascending order. Object order is determined by applying compare().

ARRAYOB SPECIES

virtual const Class* species() const
Returns a pointer to the class descriptor for class ArrayOb.

PROTECTED MEMBERS

Object I/O

virtual void storer(OIOofd& fd) const
virtual void storer(OIOout& strm) const
Applies storeOn() to each of the objects contained in this ArrayOb to store them on fd or strm.

DISABLED MEMBER FUNCTIONS

virtual Object* add(Object&)
virtual unsigned occurrencesOf(const Object&) const
virtual Object* remove(const Object&)
These functions are implemented as shouldNotImplement().

EXCEPTIONS RAISED

NIHCL_ALLOCSIZE, NIHCL_INDEXRANGE

Go to the previous, next section.