NAME
OTC_IList -
Linked list with inbuilt iterator.
SYNOPSIS
#include <OTC/collctn/ilist.hh>
template<class T>
class OTC_IList
{
public:
static os_typespec* get_os_typespec();
OTC_IList();
OTC_IList(OTC_IList<T> const& theList);
OTC_IList(OTC_IList<T> const& theList, OTC_ShallowCopy);
~OTC_IList();
OTC_IList<T>& operator=(OTC_IList<T> const& theList);
inline u_int population() const;
inline OTC_Boolean isEmpty() const;
inline T& item();
inline T const& item() const;
inline OTC_Boolean isValid() const;
inline OTC_Boolean isStart() const;
inline OTC_Boolean isEnd() const;
inline void next() const;
inline void prev() const;
inline void resetFirst() const;
inline void resetLast() const;
void apply(
OTC_Visitor<T>& theApplicator,
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
) const;
void apply(
OTC_Worker<T>& theApplicator,
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
);
void addBefore(T const& theItem);
void addAfter(T const& theItem);
inline void addFirst(T const& theItem);
inline void addLast(T const& theItem);
inline T& first();
inline T const& first() const;
inline T& last();
inline T const& last() const;
inline void removeAll();
void remove();
inline void removeFirst();
inline void removeLast();
};
CLASS TYPE
Concrete
DESCRIPTION
This class is a templated, minimal linked list, incorporating an
inbuilt iterator. This would be used where the extra functionality
of OTC_Deque or OTC_List is not required. This class
replaces the OTC_SimpleList class.
Items may be inserted at any position in the list by moving the
inbuilt iterator to the required location and then adding the
item, either before, or after the iterator position. It is also
possible to add items directly onto the head or tail of the list.
The class uses OTC_Bucket to hold items internally. Therefore,
OTC_BaseActions can be used to define what occurs when items
are added and removed from the list.
CONSTRUCTION
OTC_IList();
OTC_IList(OTC_IList<T> const& theList);
Creates a list which is a copy of
theList. If the list holds pointers,
only the pointer is copied and not
what the pointer points at.
OTC_IList(OTC_IList<T> const& theList, OTC_ShallowCopy);
Creates an alias for theList.
The same items will be referenced
by each list, however, the iterators
will be independent.
DESTRUCTION
~OTC_IList();
Invokes removeAll() to kill all buckets
in the list.
ASSIGNMENT
OTC_IList<T>& operator=(OTC_IList<T> const& theList);
Replaces this list with a copy of
theList. The iterator is reset
to being off the start of the list.
POPULATION
inline u_int population() const;
Returns the number of items in the list.
inline OTC_Boolean isEmpty() const;
Returns OTCLIB_TRUE if the list is empty.
ITERATION
inline T& item();
If the iterator is located over a valid
item, a reference to the item is returned.
If there is not a valid item under the
iterator, an exception is raised.
inline T const& item() const;
If the iterator is located over a valid
item, a reference to the item is returned.
If there is not a valid item under the
iterator, an exception is raised.
inline OTC_Boolean isValid() const;
Returns OTCLIB_TRUE if the iterator is
located over a live item.
inline OTC_Boolean isStart() const;
Returns OTCLIB_TRUE if the iterator is
located off the start of the list.
inline OTC_Boolean isEnd() const;
Returns OTCLIB_TRUE if the iterator is
located off the end of the list.
inline void next() const;
Moves the iterator onto the next item.
inline void prev() const;
Moves the iterator onto the previous item.
inline void resetFirst() const;
Moves the iterator to the first item in
the list. If the list is empty, the
iterator will be placed off the end of
the list.
inline void resetLast() const;
Moves the iterator to the last item in
the list. If the list is empty, the
iterator will be placed off the start of
the list.
APPLICATORS
void apply(
OTC_Visitor<T>& theApplicator,
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
) const;
Applies theApplicator to each of the
items in the collection. The direction
being determined by theDirection. Valid
values are OTCLIB_FORWARD and
OTCLIB_BACKWARD.
void apply(
OTC_Worker<T>& theApplicator,
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
);
Applies theApplicator to each of the
items in the collection. The direction
being determined by theDirection. Valid
values are OTCLIB_FORWARD and
OTCLIB_BACKWARD.
ADDITION
void addBefore(T const& theItem);
Adds theItem before the item where the
iterator is currently located. If the
iterator is located off the end of the
list, the effect is that theItem is
appended to the list. If the iterator is
off the start of the list, the effect
is that theItem is prepended to the
list. After the operation, the iterator
will be located on the newly inserted
item.
void addAfter(T const& theItem);
Adds theItem after the item where the
iterator is currently located. If the
iterator is located off the end of the
list, the effect is that theItem is
appended to the list. If the iterator is
off the start of the list, the effect
is that theItem is prepended to the
list. After the operation, the iterator
will be located on the newly inserted
item.
inline void addFirst(T const& theItem);
Adds theItem at the head of the list.
The location of the iterator is unchanged.
inline void addLast(T const& theItem);
Adds theItem after the last item in
the list. The location of the iterator
is unchanged.
LOOKING
inline T& first();
If the list is not empty, a reference
is returned to the item on the head of
the list. If the list is empty, an
exception is raised.
inline T const& first() const;
If the list is not empty, a reference is
returned to the item on the head of the
list. If the list is empty, an exception
is raised.
inline T& last();
If the list is not empty, a reference is
returned to the last item in the list. If
the list is empty, an exception is raised.
inline T const& last() const;
If the list is not empty, a reference is
returned to the last item in the list. If
the list is empty, an exception is raised.
REMOVING
inline void removeAll();
Kills all buckets holding items in the
list. The iterator is reset to being off
the start of the list.
void remove();
If the iterator is located over a valid
item, the bucket which is holding the item
is killed. The bucket is only unlinked
from the list and destroyed when the
iterator is moved. If the iterator is
not over a valid link within the list,
an exception is raised.
inline void removeFirst();
If the list is not empty, the first
item in the list is killed. If the
internal iterator is not located on
the first item, it will be removed
immediately. If the list were empty,
an exception is raised.
inline void removeLast();
If the list is not empty, the last
item in the list is killed. If the
internal iterator is not located on
the first item, it will be removed
immediately. If the list were empty,
an exception is raised.
SEE ALSO
OTC_Bucket, OTC_BaseActions
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED