Add has_hook functions taking function pointer or callback data in EventHandler

This commit is contained in:
Younguk Kim 2017-09-24 02:46:00 +09:00
parent 1583196022
commit b71ee446e3
2 changed files with 43 additions and 0 deletions

View File

@ -182,6 +182,46 @@ has_hook(const string &event_name) const {
} }
/**
* Returns true if there is the hook added on the indicated event name and
* function pointer, false otherwise.
*/
bool EventHandler::
has_hook(const string &event_name, EventFunction *function) const {
assert(!event_name.empty());
Hooks::const_iterator hi;
hi = _hooks.find(event_name);
if (hi != _hooks.end()) {
const Functions& functions = (*hi).second;
if (functions.find(function) != functions.end()) {
return true;
}
}
return false;
}
/**
* Returns true if there is the hook added on the indicated event name,
* function pointer and callback data, false otherwise.
*/
bool EventHandler::
has_hook(const string &event_name, EventCallbackFunction *function, void *data) const {
assert(!event_name.empty());
CallbackHooks::const_iterator chi;
chi = _cbhooks.find(event_name);
if (chi != _cbhooks.end()) {
const CallbackFunctions& cbfunctions = (*chi).second;
if (cbfunctions.find(CallbackFunction(function, data)) != cbfunctions.end()) {
return true;
}
}
return false;
}
/** /**
* Removes the indicated function from the named event hook. Returns true if * Removes the indicated function from the named event hook. Returns true if
* the hook was removed, false if it wasn't there in the first place. * the hook was removed, false if it wasn't there in the first place.

View File

@ -55,6 +55,9 @@ public:
bool add_hook(const string &event_name, EventCallbackFunction *function, bool add_hook(const string &event_name, EventCallbackFunction *function,
void *data); void *data);
bool has_hook(const string &event_name) const; bool has_hook(const string &event_name) const;
bool has_hook(const string &event_name, EventFunction *function) const;
bool has_hook(const string &event_name, EventCallbackFunction *function,
void *data) const;
bool remove_hook(const string &event_name, EventFunction *function); bool remove_hook(const string &event_name, EventFunction *function);
bool remove_hook(const string &event_name, EventCallbackFunction *function, bool remove_hook(const string &event_name, EventCallbackFunction *function,
void *data); void *data);