Go to the previous, next section.
#include <nihcl/OrderedCltn.h>
Class
OrderedCltn
implements a variable-length array of pointers to objects. Object pointers are indexed originating at 0, with index range checking. The member function
add()
appends objects to the end of the array at index
size()
.
OrderedCltn(unsigned
capacity
=DEFAULT_CAPACITY)
OrderedCltn
that can hold up to
capacity
objects. An
NIHCL_ALLOCSIZE
error is raised if
capacity
is not greater than 0. If an attempt is made to add more than
capacity
objects to an
OrderedCltn
,
reSize()
is called to increase its capacity.
virtual Object* add(Object&
ob)
virtual Object* addLast(Object&
ob)
OrderedCltn
and return a pointer to
ob.
virtual Object* addAfter(const Object&
ob, Object&
newob)
virtual Object* addBefore(const Object&
ob, Object&
newob)
OrderedCltn
that is
isEqual()
to
ob, inserts
newob
before or after it, and returns a pointer to
newob. If no object equal to
ob
is found, an
NIHCL_OBNOTFOUND
error is raised. Since the addition of an object pointer at any position other than at the end of an
OrderedCltn
causes the pointers above it to be moved up, applications using large
OrderedCltn
s that require many insertions will perform those operations more efficiently with a
LinkedList
.
virtual Object* addAllLast(const OrderedCltn&
cltn)
OrderedCltn
cltn
to the end of this
OrderedCltn
and returns a pointer to
cltn.
virtual Collection& addContentsTo(Collection&
cltn) const
OrderedCltn
to
cltn
and returns a pointer to
cltn.
virtual void atAllPut(Object&
ob)
OrderedCltn
with pointers to object
ob.
virtual void replaceFrom(int
start, int
stop, const SeqCltn&
replacement, int
startAt=0)
OrderedCltn
with those in
SeqCltn
replacement
starting at index
startAt.
virtual Object* remove(const Object&
ob)
isEqual()
to
ob
from this
OrderedCltn
and returns a pointer to the removed object. If no equal object is found
nil
is returned. The
remove()
function shifts object pointers to fill the array position of the removed object, if necessary.
virtual void removeAll()
OrderedCltn
.
virtual Object* removeId(const Object&
ob)
OrderedCltn
and returns a pointer to
ob. Returns
nil
if
ob
is not found. The
removeId()
function shifts object pointers to fill the array position of the removed object, if necessary.
virtual Object* removeLast()
OrderedCltn
and returns a pointer to it. If this
OrderedCltn
is empty, an
NIHCL_CLTNEMPTY
error results.
virtual Object* after(const Object&
ob) const
virtual Object* before(const Object&
ob) const
OrderedCltn
that is
isEqual()
to
ob
and returns a pointer to the object after/before it. If the equal object is the last/first in this
OrderedCltn
,
nil
is returned. If no object equal to
ob
is found, an
NIHCL_OBNOTFOUND
error results.
virtual unsigned hash() const
Set
can use as a hash table probe. Class
OrderedCltn
implements
hash()
by exclusinve ORing the results of applying
hash()
to all objects in an
OrderedCltn
.
virtual int indexOf(const Object&
ob) const
isEqual()
to
ob
in this
OrderedCltn
. If no object is found, -1 is returned.
virtual int indexOfSubCollection(const SeqCltn&
cltn, int
start
=0) const
isEqual()
to
cltn. The search for an equal sequence begins at offset
start
in this
OrderedCltn
. If no equal sequence is found, -1 is returned.
virtual unsigned occurrencesOf(const Object&
ob) const
OrderedCltn
that are
isEqual()
to
ob.
bool operator==(const OrderedCltn&) const
bool operator!=(const OrderedCltn&) const
YES
if the left
OrderedCltn
operand is equal to (or not equal to) the right
OrderedCltn
operand.
virtual bool isEmpty() const
YES
if this
OrderedCltn
contains no objects.
virtual void deepenShallowCopy()
deepCopy()
to all the object pointers, replacing each pointer with a pointer to its copy.
Object*& operator[](int
i)
const Object *const& operator[](int
i) const
virtual Object*& at(int
i)
virtual const Object *const& at(int
i) const
OrderedCltn
. Zero-origin index is used--object pointers are indexed from 0 to
size()-1
. These functions perform a range check on the index
i
and raise an
NIHCL_INDEXRANGE
error if
i
is out of bounds.
virtual Object* first() const
virtual Object* last() const
OrderedCltn
. If this
OrderedCltn
is empty, an
NIHCL_CLTNEMPTY
exception results.
virtual unsigned capacity() const
OrderedCltn
can hold before it will need to be expanded.
virtual unsigned size() const
OrderedCltn
.
virtual void reSize(unsigned
newSize)
OrderedCltn
to
newSize. If
newSize
is less than or equal to
size()
, then the capacity is not changed.
OrderedCltn operator&(const SeqCltn&
cltn) const
OrderedCltn
that is the result of adding all of the objects in
cltn
to the end of this
OrderedCltn
.
void operator&=(const SeqCltn&
cltn)
OrderedCltn
with the result of adding all of the objects in
cltn
to the end of this
OrderedCltn
.
virtual void sort()
OrderedCltn
into ascending order. Object order is determined by applying
compare()
.
Object* addAtIndex(int
i, Object&
ob)
OrderedCltn
and returns a pointer to
ob. The object pointers originally at index positions
i
through
size()-1
are shifted up one position.
Object* removeAtIndex(int
i)
OrderedCltn
and returns the removed object pointer. The object pointers originally at index positions
i
+1
through
size()-1
are shifted down one position.
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
storeOn()
to each of the objects contained in this
OrderedCltn
to store them on
fd
or
strm.
NIHCL_CLTNEMPTY
,
NIHCL_OBNOTFOUND
Go to the previous, next section.