|
To implement a method for an entity type, the developer first defines a function to perform the desired operation for a particular entity type or types. This function takes two arguments: a pointer to
void containing the
this pointer for the calling entity, and a
const reference to
METHOD_ARGS. These arguments can be cast to the appropriate types inside the function. The function returns a logical indicating whether or not the operation was performed. Refer to Example 8-15.
|
|
|
C++ Example
|
|
|
static logical
|
|
sketch_edge(
|
|
void *entptr,
|
|
METHOD_ARGS const &argref
|
|
)
|
|
|
{
|
|
EDGE *edge = (EDGE *) entptr;
|
|
SKETCH_ARGS const &args = *(SKETCH_ARGS *) &argref;
|
|
|
// Use edge, args.color, and args.transform to create a
|
|
// DL_item storing a pointer to the DL_item in args.result
|
|
|
// The body of this has been omitted for clarity.
|
|
|
return TRUE;
|
|
}
|
|
|
Example 8-15. Define the Function
|
|
|
Next, the function is registered using the static
add_method method for the appropriate entity types. This can be done using static initializers or an initialization function for the component.
|
|
|
C++ Example
|
|
|
// Get the identifier for a method named "sketch" using
|
|
// SKETCH_ARGS
|
|
static METHOD_ID sketch_method_id("sketch", "sketch_args");
|
|
|
// Associate sketch function with sketch method for EDGE class
|
|
static MethodFunction xxx = EDGE::add_method(sketch_method_id,
|
|
sketch_edge);
|
|
|
Example 8-16. Registering the Function
|