UMap - maintains a mapping between two sets of pointers
#include <Unidraw/umap.h>
UMap is an abstract class for objects that store an arbitrary
number of pointer pairs and can search to find either member of a pair given
the other. A UMapElem object stores each pointer pair in the UMap. UMapElem
is an abstract class that defines virtuals for returning either member of
the pair, referred to as the id and the tag. Subclasses of
UMapElem redefine these virtuals to return either member of the pair they
store.
- UMapElem()
- The base class constructor does nothing by default.
- virtual void*
id()
- virtual void*
tag()
- Return the id or the tag that the UMapElem stores. Subclasses typically
define two member variables that store pair's values and redefine these
operations to return them.
- virtual
~UMap()
- The destructor deletes all UMapElem objects in the UMap.
- int Count()
- Return the number of mappings in the UMap, corresponding to the number of
UMapElems that have been registered.
- void Clear()
- Delete all the UMapElem mappings in the UMap without destroying the
UMap.
- UMap()
- The base class constructor does nothing by default.
- void
Register(UMapElem*)
- void
Unregister(UMapElem*)
- Register or remove a UMapElem from the UMap.
- int
Index(UMapElem*)
- UMapElem*
Elem(int index)
- A UMap stores its UMapElem in its _elems UArray protected member
variable. The Index operations returns the index of the given UMapElem in
the UArray, while Elem returns the UMapElem at a specified index. These
operations simply perform the corresponding operations on the UArray.
- virtual UMapElem*
FindId(void* id)
- virtual UMapElem*
FindTag(void* tag)
- FindId searches the UMap for the UMapElem element containing the given id,
while FindTag searches for the one with the given tag. These operations
perform linear searches by default, comparing their arguments against the
values that the UMapElems' id and tag operations return. The comparison is
based on the pointer values; subclasses can redefine these operations to
make more sophisticated comparisons based on the id or tags actual type.
For example, if either the id is a string, then FindId might do a string
comparison to detect a match.