Tools.h++ Manual

14-4 104011 Tandem Computers Incorporated
14
14.2 Declaring generic collection classes
All of the Tools.h++ generic collection classes are declared using the
declare
macro, defined in the header file
<generic.h>
, in a manner similar to the
example above. However, there is one important difference in how the
Tools.h++ classes are declared versus the pattern set by Stroustrup (1986,
Section 7.3.5). This is summarized below:
typedef int* intP;
declare(RWGStack, intP) // Wrong!
declare(RWGStack, int) // Correct.
In Stroustrup, the class is declared using a typedef for a pointer to the collected
item. The Tools.h++ generic classes are all declared using the item name itself.
This is true for both the reference- and value-semantics classes.
14.3 User-defined functions
Some of the member functions of the generic collection classes require a
pointer to a user-defined function. There are two kinds, discussed in the
following two sub-headings.
Tester functions
The first kind of user-defined function is a "tester function". It has the form:
RWBoolean
tester
(const
type
* ty, const void* a)
where tester is the name of the function, type is the type of the members of the
collection class, and
RWBoolean
is a typedef for an int (whose only possible
values are
TRUE
or
FALSE
). The job of the tester function is to signal when a
certain member of the collection has been identified. The decision of how this
is done, or what it means to have "identified" an object, is left to the user. The
user can choose to compare addresses (test for two objects being "identical"), or
look for certain values within the object (test for "isEqual"). The first variable
ty
will point to a member of the collection and can be thought of as a
"candidate". The second variable a is available for your use to be tested against
ty for a match. It can be thought of as "client data", used to make the decision
of whether there is a match.