Add safe bool conversion to ninic function pointer semantic
This commit is contained in:
parent
5908e3600d
commit
57e69cb0d0
1 changed files with 19 additions and 0 deletions
|
@ -111,6 +111,19 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
typedef void (FunctionPointerWithContext::*bool_type)() const;
|
||||
|
||||
/**
|
||||
* implementation of safe bool operator
|
||||
*/
|
||||
operator bool_type() const {
|
||||
if(_function || _memberFunctionAndPointer._object) {
|
||||
return &FunctionPointerWithContext::trueValue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up an external FunctionPointer as a next in the chain of related
|
||||
* callbacks. Invoking call() on the head FunctionPointer will invoke all
|
||||
|
@ -156,6 +169,12 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief True value used in conversion to bool, this function is useless
|
||||
* beside this usage
|
||||
*/
|
||||
void trueValue() const {}
|
||||
|
||||
struct MemberFunctionAndPtr {
|
||||
/*
|
||||
* Forward declaration of a class and a member function to this class.
|
||||
|
|
Loading…
Reference in a new issue