FPointer - A callback system that allows for 32bit unsigned ints to be passed to and from the callback.
Dependents: FYPFinalProgram FYPFinalizeProgram KEYS SaveKeypad ... more
Diff: FPointer.h
- Revision:
- 1:d7803001a259
- Parent:
- 0:fcfb13f40846
- Child:
- 2:56e309e76c19
diff -r fcfb13f40846 -r d7803001a259 FPointer.h --- a/FPointer.h Tue Jan 18 17:31:19 2011 +0000 +++ b/FPointer.h Tue Jan 18 22:40:19 2011 +0000 @@ -52,7 +52,7 @@ * data structure thus allowing the callback to again get the values. * * Note, when passing pointers to variables to the callback, if the callback - * function/method changes that variables value then it will also change the + * function/method changes that variable's value then it will also change the * value the caller sees. If C pointers are new to you, you are strongly * advised to read up on the subject. It's pointers that often get beginners * into trouble when mis-used. @@ -67,10 +67,10 @@ protected: - // C callback function pointer for to pass read data to. + //! C callback function pointer. uint32_t (*c_callback)(uint32_t); - // C++ callback object/method pointer for to pass read data to. + //! C++ callback object/method pointer. FPointerDummy *obj_callback; uint32_t (FPointerDummy::*method_callback)(uint32_t); @@ -114,20 +114,44 @@ method_callback = (uint32_t (FPointerDummy::*)(uint32_t))method; } - /** call + /** call - Overloaded callback initiator. * * call the callback function. + * * @param uint32_t The value to pass to the callback. * @return uint32_t The value the callback returns. */ uint32_t call(uint32_t arg) { - if (c_callback != NULL) return (*c_callback)(arg); + if (c_callback != NULL) { + return (*c_callback)(arg); + } else { - if (obj_callback != NULL && method_callback != NULL) + if (obj_callback != NULL && method_callback != NULL) { return (obj_callback->*method_callback)(arg); + } } - return 0; + return (uint32_t)NULL; } + + /** call - Overloaded callback initiator. + * + * Call the callback function without passing an argument. + * The callback itself is passed NULL. Note, the callback + * prototype should still be <b>uint32_t callback(uint32_t)</b>. + * + * @return uint32_t The value the callback returns. + */ + uint32_t call(void) { + if (c_callback != NULL) { + return (*c_callback)((uint32_t)NULL); + } + else { + if (obj_callback != NULL && method_callback != NULL) { + return (obj_callback->*method_callback)((uint32_t)NULL); + } + } + return (uint32_t)NULL; + } }; }; // namespace AjK ends