From 9b0b705c66269b8488d9b9806d89e236d10d8c83 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 2 Jan 2015 23:36:51 +0100 Subject: allowing to pass data to event handlers --- src/core/managed/Events.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/core/managed/Events.hpp') diff --git a/src/core/managed/Events.hpp b/src/core/managed/Events.hpp index 90dabec..177824c 100644 --- a/src/core/managed/Events.hpp +++ b/src/core/managed/Events.hpp @@ -74,8 +74,9 @@ enum class EventType : int { * @param event is a reference to the object holding the event data. * @param owner is a reference to the managed object that was given in the * registerEventHandler function. + * @param data is some user defined data. */ -using EventHandler = void (*)(const Event &event, Managed* owner); +using EventHandler = void (*)(const Event &event, Managed *owner, void *data); /** * The Event class and its child classes are responsible for containing the @@ -126,9 +127,7 @@ struct NameChangeEvent : public Event { * copied, only the reference is passed around. */ NameChangeEvent(const std::string &oldName, const std::string &newName) - : Event(EventType::NAME_CHANGE), - oldName(oldName), - newName(newName) + : Event(EventType::NAME_CHANGE), oldName(oldName), newName(newName) { } }; @@ -152,6 +151,11 @@ struct EventHandlerDescriptor { */ Managed *owner; + /** + * User defined data. + */ + void *data; + /** * Constructor of the EventHandlerDescriptor struct. * @@ -162,11 +166,11 @@ struct EventHandlerDescriptor { * going to be called. This can be used to make sure that the method which * handles the events has access to its owned object as long as the event * handler lives. + * @param data is some arbitrary user defined data. */ - EventHandlerDescriptor(EventType type, EventHandler handler, Managed *owner) - : type(type), - handler(handler), - owner(owner) + EventHandlerDescriptor(EventType type, EventHandler handler, Managed *owner, + void *data) + : type(type), handler(handler), owner(owner), data(data) { } }; -- cgit v1.2.3