Menu

Home

Timothy Hollies

Delayed Dispatch Library

The 'delayed' library provides a way to queue function calls to be called at a later date. This allows dynamic dispatch, more control over when functions are called, and greatly reduces code dependency.

[ Member Functions ]
[ Best Usage ]
[ Design ]


QUICKSTART:

The core object of the library is the 'dispatch_manager'. It provides an interface to the rest of the library:

delayed::dispatch_manager<delayed::adler32> dispatchManager;</delayed::adler32>

The function parameter is a policy which defines how the id field of the managers member functions are converted into an integer for lookup. The two provided policies are 'SimpleInt' which makes the id field require an integer, and 'Adler32' which generates an integer using an Adler32 sum and makes the id field require a char*.

Functions need to be registered with the manager before they can be called. Only functions which return bool and have 8 or fewer arguments of any type can be registered.

bool someFunction(int a, float b)
{
//code
return true;
}

dispatchManager.connect("test", someFunction);

This registers 'someFunction' with 'dispatchManager' with the hash generated from the string "test". To queue a call use the "queue_call" member function of dispatch_manager.

dispatchManager.queue_call("test", 1, 2.0f);

The first parameter is the id of the function to be called, this is the same as when it was registered. The following parameters are the parameters to be passed to the function, if incorrect parameters are passed a runtime assertion will be triggered. Currently implicit type conversions do not work. To dispatch queued calls call the 'dispatch' member function of dispatch_manager.

dispatchManager.dispatch();

The calls are now dispatched in the order they were queued.