Go to the previous, next section.
#include <nihcl/ArrayOb.h>
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.
ArrayOb(unsigned
capacity
=DEFAULT_CAPACITY)
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)
ArrayOb
that is the same size as
ArrayOb
a
and initializes it to point to the same objects contained in
a.
virtual Collection& addContentsTo(Collection&
cltn) const
ArrayOb
to the
Collection
cltn.
virtual void removeAll()
ArrayOb
and replaces them with pointers to the
nil
object.
virtual unsigned hash() const
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
.
bool operator==(const ArrayOb&) const
bool operator!=(const ArrayOb&) const
YES
if the left
ArrayOb
operand is equal to (or not equal to) the right
ArrayOb
operand.
virtual int compare(const Object&
a) const
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.
virtual bool isEqual(const Object&
a) const
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
.
void operator=(const ArrayOb&)
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()
deepCopy()
to all the object pointers, replacing each pointer with a pointer to its copy.
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
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.
virtual unsigned capacity() const
virtual unsigned size() const
ArrayOb
.
virtual void reSize(unsigned
newSize)
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.
virtual Object* doNext(Iterator&
pos) const
ArrayOb
, or 0 if no more objects remain. The
Iterator
argument
pos
maintains the current position in the
ArrayOb
.
virtual void sort()
ArrayOb
into ascending order. Object order is determined by applying
compare()
.
virtual const Class* species() const
ArrayOb
.
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
storeOn()
to each of the objects contained in this
ArrayOb
to store them on
fd
or
strm.
virtual Object* add(Object&)
virtual unsigned occurrencesOf(const Object&) const
virtual Object* remove(const Object&)
shouldNotImplement()
.
NIHCL_ALLOCSIZE
,
NIHCL_INDEXRANGE
Go to the previous, next section.