Chapter 4. Writing a TPT callback function

Table of Contents

What is a callback?
Uses for Callbacks
The Callback Interface
TPT Callbacks and Security

What is a callback?

In C++, it is sometimes handy to specify that a library function call a user defined function for customizable behavior. In the standard library, the generic binary search and quick sort functions do this.

void *bsearch( const void *key, const void *base, size_t num, size_t width, int
	(*compare ) ( const void *elem1, const void *elem2 ) );
void qsort( void *base, size_t num, size_t width, int (*compare )(const void
	*elem1, const void *elem2 ) );

Each of these functions allows the user to specify a custom compare function for a user defined data type. LibTPT provides a similar method to allow the user to specify a C++ function that will be called from a TPT template.