home *** CD-ROM | disk | FTP | other *** search
- Compendium - C++ Container Class Library
- Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
- ------------------------------------------------------------------------------
-
-
- Compendium Version 1.1
- C++ Container Classes
-
-
- Compendium is a library of container classes for C++ development. This
- library provides a full set of both object based (smalltalk-like) containers
- and template based containers. Compendium works with DOS, Windows, and
- WIN32 programs using Borland C++. There is also a unix version available
- which has been compiled and tested using cfront on Sun, HP, and SGI work-
- stations as well as the xlC compiler on IBM. Future ports to other compilers
- will happen as requests and resources permit.
-
- Object Based Containers
- -----------------------
- The object based library is a full set of containers where the objects
- to be added must derive (directly or indirectly) from a common base class
- called "CmObject". These containers take, as input, pointers to these
- objects. The objects are not copied, only the pointers. This means that
- the objects must be dynamically allocated using the "new" operator. All
- of the object based containers derive from the class "CmContainer" and
- share certain core behavior. For example, and object can be added to any
- container using the function "add" and removed using the function "remove".
- The virtual functions in "CmContainer" shared by all containers are:
-
- CmObject* operator[] (int idx) const; // Return object at index.
- unsigned size () const; // Return container size.
- Bool add (CmObject*); // Add object to container.
- Bool remove (CmObject*); // Remove first equal object.
- CmObject* lookup (CmObject*) const; // Return pointer to equal.
- Bool contains (CmObject*) const; // See if equal object is in.
- unsigned occurrences(CmObject*) const; // Return number of equal objects.
- void removeAll (); // Remove all objects.
- Bool isEmpty () const; // See if container is empty.
- CmIterator* newIterator() const; // Create and return an iterator.
-
- Every type of container also defines an iterator class. An iterator is an
- object used to cycle through the contents of a container. All iterator
- classes derive from the class "CmIterator" and share the same behavior.
- The iterator functions are:
-
- Bool done () const; // See if iterator reached container limit.
- CmObject* next (); // Return object and advance to next.
- CmObject* previous(); // Return object and backup to previous.
- CmObject* current () const; // Return current object.
- void first (); // Move iterator to first object.
- void last (); // Move iterator to last object.
-
- Remembering that the container contains pointers to objects that you
- allocate, what happens when a container is deleted. The container function
- "ownsObjects" allows you to set whether or not a container owns it's objects.
- A container that owns it's objects will delete them when the container is
- destroyed or when objects are removed. Also a container that owns it's
- objects will copy the objects when the container is copied. Conversely,
- a container that does not own it's objects will never delete them and
- when the container is copied, only the pointers will be copied leaving
- two containers pointing to the same objects. Use this carefully.
-
- As mentioned previously, any object to be inserted into a container must
- derive from "CmObject". The class "CmObject" has pure virtual functions
- that must be defined for every class. These are:
-
- char* isA () const; // Return the class name.
- Bool isA (const char*) const; // See if input matches class name.
- Bool isTypeOf(const char*) const; // See if input is parent class name.
- CmObject* newCopy () const; // Create a copy and return pointer.
-
- These functions can be defined in the derived class simply by making a
- one line macro call. The macro is "CMOBJECT_DEFINE(class, parent)" where
- class is the class name and parent is the parent class name. The class
- "CmObject" also contains several virtual functions which can be optionally
- redefined to control container behavior. These are:
-
- Bool isEqual(CmObject*) const; // See if input object is equal to this.
- int compare(CmObject*) const; // Compare input object to this.
- // 0-equal, -1-this<input, 1-this>input
- unsigned hash(unsigned) const; // Perform hash with input table size.
-
- Template Based Containers
- -------------------------
- The Compendium library also provides a full set of template based containers.
- These containers were designed, using the C++ template mechanism, to hold
- any kind of data including the standard C types. The only catch is that any
- data type to be added to a container template must have all of the lexical
- operators defined (<, <=, >, >=, ==, !=). The template containers all take
- item references as input and the items are copied into the container. This
- means that user defined types must have copy constructors and assignment
- operators defined. As with the object based containers, all template based
- containers derive from a common base class called "CmTContainer<T>" where T
- denotes the data type. The virtual functions in "CmTContainer<T>" shared by
- all template containers are:
-
- const T& operator[] (int idx) const; // Return item at index.
- unsigned size () const; // Return container size.
- Bool add (const T&); // Add item to container.
- Bool remove (const T&); // Remove first equal item.
- const T& lookup (const T&) const; // Return first equal item.
- Bool contains (const T&) const; // See if equal item exists.
- unsigned occurrences(const T&) const; // Return number of equal items.
- void removeAll (); // Remove all items.
- Bool isEmpty () const; // See if container is empty.
- CmTIterator<T>* newIterator() const; // Create and return an iterator.
-
- Every type of container template also defines an iterator template. An
- iterator is an object used to cycle through the contents of a container.
- All iterator templates derive from the class "CmTIterator<T>" and share
- the same behavior. The iterator functions are:
-
- Bool done () const; // See if iterator reached container limit.
- const T& next (); // Return item and advance to next.
- const T& previous(); // Return item and backup to previous.
- const T& current () const; // Return current item.
- void restart (); // Restart iteration at beginning.
- void toEnd (); // Move iterator to last item.
-
- See the file "CLASSES.LST" for the complete Compendium class list. And
- remember that registering Compendium gets you a complete programmer's
- guide and reference manual. For registration information, see the file
- "READ.ME".
-
- Improvements and Changes from version 1.0
- -----------------------------
- * several small bug fixes discovered in-house and by users,
- * improved performance in object I/O from the reserve,
- * added iterator functionality,
- * Max, min, and abs template functions.
- * Looping macros.
- * New support for Sun (Solaris), HP (HP-UX), SGI (IRIX), and IBM (AIX).
- * a better installation mechanism.
- * New "firstThat" functions in "CmContainer" and "CmReserve" class.
- * Iterator functions "restart" and "toEnd" are now "first" and "last".
- * Output arguments of several template functions in both "CmTContainer"
- and "CmTIterator" were changed from "T" to "const T&".
- * Remove "isOld" and "isNew" functions from "CmReserve" and added a
- single "exists" function.
-