mbed libraries for KL25Z
Diff: FunctionPointer.h
- Revision:
- 7:73c5efe92a6c
- Parent:
- 0:8024c367e29f
- Child:
- 8:c14af7958ef5
--- a/FunctionPointer.h Fri Oct 12 10:06:08 2012 +0000 +++ b/FunctionPointer.h Tue Oct 23 09:20:18 2012 +0000 @@ -1,7 +1,6 @@ /* mbed Microcontroller Library - FunctionPointer * Copyright (c) 2007-2009 ARM Limited. All rights reserved. - */ - + */ #ifndef MBED_FUNCTIONPOINTER_H #define MBED_FUNCTIONPOINTER_H @@ -13,9 +12,7 @@ * A class for storing and calling a pointer to a static or member void function */ class FunctionPointer { - public: - /* Constructor FunctionPointer * Create a FunctionPointer, attaching a static function * @@ -31,11 +28,11 @@ * object - The object pointer to invoke the member function on (i.e. the this pointer) * function - The address of the void member function to attach */ - template<typename T> + template<typename T> FunctionPointer(T *object, void (T::*member)(void)) { attach(object, member); } - + /* Function attach * Attach a static function * @@ -58,16 +55,15 @@ _membercaller = &FunctionPointer::membercaller<T>; _function = 0; } - + /* Function call - * Call the attached static or member function - */ + * Call the attached static or member function (safe to be called even if there is no handler) + */ void call(); - + private: - template<typename T> - static void membercaller(void *object, char *member) { + static void membercaller(void *object, char *member) { T* o = static_cast<T*>(object); void (T::*m)(void); memcpy((char*)&m, member, sizeof(m));