// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code so the library containing
// the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
- Dispatcher dispatcher = callback.mImpl->mMemberFunctionDispatcher;
+ Dispatcher dispatcher = callback.mImpl.mMemberFunctionDispatcher;
(*dispatcher)(callback);
}
// its also possible to have a member function pointer to a CallbackProvider
// that has been deleted, so check if we have impl still
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
(*(callback.mFunction))();
}
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code so the library containing
// the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = R (*)(CallbackBase&);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
returnVal = (*dispatcher)(callback);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
using Function1 = R (*)();
returnVal = (*(reinterpret_cast<Function1>(callback.mFunction)))();
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = void (*)(CallbackBase&, P1);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
(*dispatcher)(callback, param1);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function1 = void (*)(P1);
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = R (*)(CallbackBase&, P1);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
returnVal = (*dispatcher)(callback, param1);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function1 = R (*)(P1);
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = void (*)(CallbackBase&, P1, P2);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
(*dispatcher)(callback, param1, param2);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function2 = void (*)(P1, P2);
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = R (*)(CallbackBase&, P1, P2);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
returnVal = (*dispatcher)(callback, param1, param2);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function2 = R (*)(P1, P2);
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = void (*)(CallbackBase&, P1, P2, P3);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
(*dispatcher)(callback, param1, param2, param3);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function2 = void (*)(P1, P2, P3);
// otherwise call the dispatcher function that knows the real type of the object
// Note that this template dispatcher lives in client code (where the callback was created)
// so the library containing the code has to be loaded, otherwise we crash boom bang
- if(callback.mImpl && callback.mImpl->mObjectPointer)
+ if(callback.mImpl.mObjectPointer)
{
using Dispatcher = R (*)(CallbackBase&, P1, P2, P3);
- Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl->mMemberFunctionDispatcher);
+ Dispatcher dispatcher = reinterpret_cast<Dispatcher>(callback.mImpl.mMemberFunctionDispatcher);
returnVal = (*dispatcher)(callback, param1, param2, param3);
}
- else if(!callback.mImpl && callback.mFunction)
+ else if(callback.mFunction)
{
// convert function type
using Function2 = R (*)(P1, P2, P3);
*/
struct Impl
{
- Impl(); ///< Default constructor @SINCE_1_0.0
-
- void* mObjectPointer; ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
- Dispatcher mMemberFunctionDispatcher; ///< Dispatcher for member functions
- Destructor mDestructorDispatcher; ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
+ void* mObjectPointer{nullptr}; ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
+ Dispatcher mMemberFunctionDispatcher{nullptr}; ///< Dispatcher for member functions
+ Destructor mDestructorDispatcher{nullptr}; ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
};
- Impl* mImpl; ///< Implementation pointer
+ Impl mImpl;
union
{
* @param[in] rhs A reference to compare to
* @return True if lhs is same as rhs
*/
-bool operator==(const CallbackBase& lhs, const CallbackBase& rhs);
+inline bool operator==(const CallbackBase& lhs, const CallbackBase& rhs)
+{
+ if (lhs.mFunction == rhs.mFunction &&
+ lhs.mImpl.mObjectPointer == rhs.mImpl.mObjectPointer)
+ {
+ return true;
+ }
+ return false;
+}
/**
* @brief Dispatcher to delete an object.
static void Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)();
static void Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)(P1);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(param1);
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)(P1, P2);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(param1, param2);
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)(P1, P2, P3);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(param1, param2, param3);
static R Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = R (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
return (object->*function)();
static R Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = R (T::*)(P1);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
return (object->*function)(param1);
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = R (T::*)(P1, P2);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
return (object->*function)(param1, param2);
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = R (T::*)(P1, P2, P3);
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
return (object->*function)(param1, param2, param3);
static void Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
(*object)();
}
};
static void Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
(*object)(param1);
}
};
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
(*object)(param1, param2);
}
};
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
(*object)(param1, param2, param3);
}
};
static R Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
return (*object)();
}
};
static R Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
return (*object)(param1);
}
};
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
return (*object)(param1, param2);
}
};
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
return (*object)(param1, param2, param3);
}
};
static void Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)();
static void Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static void Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static R Dispatch(CallbackBase& callback)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static R Dispatch(CallbackBase& callback, P1 param1)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);
static R Dispatch(CallbackBase& callback, P1 param1, P2 param2, P3 param3)
{
// "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast<T*>(callback.mImpl->mObjectPointer);
+ T* object = reinterpret_cast<T*>(callback.mImpl.mObjectPointer);
using MemberFunction = void (T::*)();
MemberFunction function = reinterpret_cast<MemberFunction>(callback.mMemberFunction);
(object->*function)(/*ignore params*/);