BurgerLib
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
Burger::FunctionList Class Reference

Simple manager of a list of function pointers. More...

#include <rqrunqueue.h>

Collaboration diagram for Burger::FunctionList:
Collaboration graph
[legend]

List of all members.

Classes

struct  FunctionEntry_t

Public Types

typedef void(BURGER_APICallback )(void *)
 Function pointer type for callbacks.

Public Member Functions

 FunctionList ()
 FunctionList constructor.
 ~FunctionList ()
 FunctionList destructor.
void Call (void)
 Invoke every function stored within the list.
Word Add (Callback pProc, void *pData=NULL)
 Add a function to the head of the list.
Word Find (Callback pProc)
 Return TRUE if a function is in the list.
Word Find (Callback pProc, void *pData)
 Return TRUE if a function is in the list.
Word RemoveAll (Callback pProc)
 Remove all entries to a function from the list.
Word Remove (Callback pProc, void *pData=NULL)
 Remove a function from the list.
void Clear (void)
 Release all function entries.

Private Member Functions

 FunctionList (const FunctionList &)
 Don't use.
FunctionList operator= (const FunctionList &)
 Don't use.

Private Attributes

FunctionEntry_tm_pFirst
 Pointer to the first entry.
Word m_Recurse
 TRUE if this class is the process of executing.

Detailed Description

Simple manager of a list of function pointers.

FunctionList will hold a list of simple function pointers and call them when the Call() member is invoked. It's useful for creating a list of functions to be called in the background on a demand basis, such as polling tasks and game logic objects.

Each function is of a type of void (BURGER_API *)(void *pData);

Note:
Due to the nature of memory use, the copying of this class is forbidden.

Member Typedef Documentation

Function pointer type for callbacks.

When the Call() function is invoked, all functions will be called using this type of "void (BURGER_API *)(void *pData);" with a single parameter that will have either a user supplied void * or a zero if none was supplied.


Constructor & Destructor Documentation

FunctionList constructor.

Initialize the class to contain no list. This is inlined due to its only zeroing out members.

FunctionList destructor.

This will call Clear() and dispose of all the memory allocated. No functions will be called.

See also:
Clear().

Don't use.


Member Function Documentation

Word Burger::FunctionList::Add ( Callback  pProc,
void pData = NULL 
)

Add a function to the head of the list.

Given a function pointer and a pointer to data to pass to the function pointer, add this entry to the list of functions that are to be called with each call to Call(). The pointer pData is not used by this class and it's solely used as a parameter when the function pointer is called.

Parameters:
pProcPointer to a function of type Burger::FunctionList::Callback.
pDataPointer to be passed to the function when called.
Returns:
Returns TRUE if successful, FALSE if out of memory or if the function pointer was NULL.
See also:
Remove(Callback,void*).

Invoke every function stored within the list.

Traverse the array of functions to call and invoke each and every one of them. The functions may add new entries to the list or remove themselves if they need to. If Add() is called, execution of the new entry will be deferred until the next time Call() is invoked.

The function called is of type Burger::FunctionList::Callback.

Note:
This function can take a significant amount of CPU time if the functions invoked are very slow. This function runs with minimal overhead.
There is a recursion checker, this function will do nothing if it is called by a Burger::FunctionList::Callback proc.
See also:
Add(Callback,void*), Remove(Callback,void*) or Remove(Callback);

Release all function entries.

Release all of the allocated memory and discard all function and data pointers.

Note:
No functions will be called. Only the list will be destroyed.
See also:
Add(Callback,void*) or Remove(Callback,void*).

Return TRUE if a function is in the list.

Given a function pointer, search the list to see if there is a match. If a match is found, return TRUE.

Parameters:
pProcPointer to the function.
Returns:
TRUE if the function pointer was found, FALSE if not.
See also:
Add(Callback,void*), Clear() or Call().
Word Burger::FunctionList::Find ( Callback  pProc,
void pData 
)

Return TRUE if a function is in the list.

Given a function pointer and a pointer to data to pass to the function pointer, search the list to see if there is a match. If a match is found, return TRUE.

Parameters:
pProcPointer to the function.
pDataVoid pointer to pass to the function if called.
Returns:
TRUE if the Function/Data pair was found, FALSE if not.
See also:
Add(Callback,void*), Find(CallBack) or Call().
FunctionList Burger::FunctionList::operator= ( const FunctionList ) [private]

Don't use.

Word Burger::FunctionList::Remove ( Callback  pProc,
void pData = NULL 
)

Remove a function from the list.

Given a function pointer and a pointer to data to pass to the function pointer, search the list to see if there is a match. If a match is found, remove the entry and return TRUE, saying I found it.

Note:
Functions can remove themselves from the list at exection time, but you cannot remove a different function during your time quantum since it might break the linked list travesal. If you wish to remove other entries, you must defer this action.
Parameters:
pProcPointer to the function.
pDataVoid pointer to pass to the function if called.
Returns:
TRUE if the Function/Data pair was found, FALSE if not.
See also:
Add(Callback,void*), Clear() or Call().

Remove all entries to a function from the list.

Given a function pointer and a pointer to data to pass to the function pointer, search the list to see if there is a match. If a match is found, remove the entry and return TRUE, saying I found it.

Note:
This function should not be invoked while Call() is executing. It may cause a list traversal error.
Parameters:
pProcPointer to the function.
Returns:
TRUE if the Function/Data pair was found, FALSE if not.
See also:
Add(Callback,void*), Clear() or Call().

Member Data Documentation

Pointer to the first entry.

TRUE if this class is the process of executing.