User-defined functions, Tester functions – HP Integrity NonStop J-Series User Manual
Page 145

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
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 of these user-defined functions, discussed in the
following two sections.
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. You can choose to compare addresses (test for two objects being identical), or to
look for certain values within the object (test for isEqual). The first variable ty, which can be
thought of as a candidate, will point to a member of the collection. The second variable a,
which can be thought of as client data, can be tested against ty for a match.
In the following example, which expands on the previous one, the problem is to test for isEqual.
We push some values onto a stack to see if a certain value exists on the stack. The member
function contains() of class
RWGStack(type)
has prototype:
RWBoolean contains(RWBoolean (*t)(const type*, const void*),
const void* a) const;
The first argument is RWBoolean (*t)(const type*, const void*). This is a pointer to the tester
function, for which we will have to provide an appropriate definition:
#include
#include
declare(RWGStack, int)
RWBoolean myTesterFunction(const int* jp, const void* a) //1
{ return *jp == *(const int*)a; //2