NAME

OTC_Collection - Abstract base class for a collection of objects.

SYNOPSIS


#include <OTC/collctn/collctn.hh>

template<class T>
class OTC_Collection
{
  public:
    virtual ~OTC_Collection();
    OTC_Collection();
    virtual void removeAll();
    virtual OTC_Boolean isEmpty() const;
    virtual u_int population() const;
    virtual OTC_Iterator<T> items(
      OTC_Protection theProtection=OTCLIB_SAFE
    ) const;
};

CLASS TYPE

Concrete

DESCRIPTION

This class is the ultimate base class of any collection. It embodies the abstractions that all collections must provide. These are:

EXAMPLE

An example of how a collection class could be used. If a function only requires the ability to iterate over a collection as above, the function should be written to accept the collection base class. This would allow any type of collection to be passed to the function and not just the particular one that was being used at that time.

CONSTRUCTION

OTC_Collection();

DESTRUCTION

virtual void removeAll();

ENQUIRY

virtual OTC_Boolean isEmpty() const;
virtual u_int population() const;

ITERATION

virtual OTC_Iterator<T> items(
  OTC_Protection theProtection=OTCLIB_SAFE
) const;

NOTES

removeAll(), population() and items() must be redefined in a derived class. isEmpty() should also be redefined in a derived class if possible, as the default for isEmpty() is to compare the result of population() against 0. This is potentially inefficient, depending on the implementation of a particular collection. It is possible to create an instance of the OTC_Collection class. If you do, it will behave like an empty collection, always returning a population of 0 and a null iterator.

SEE ALSO

OTC_Iterator

LIBRARY

OTC

AUTHOR(S)

Graham Dumpleton

COPYRIGHT

Copyright 1991 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED