summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-02 23:36:51 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-01-02 23:36:51 +0100
commit9b0b705c66269b8488d9b9806d89e236d10d8c83 (patch)
tree372ab00b4c62422f99c1505326a7edc85ce5809f /src/core
parentf853859983b7b3ddf771bbc48c6c312a73516a37 (diff)
allowing to pass data to event handlers
Diffstat (limited to 'src/core')
-rw-r--r--src/core/managed/Events.hpp20
1 files changed, 12 insertions, 8 deletions
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)
{
}
};
@@ -153,6 +152,11 @@ struct EventHandlerDescriptor {
Managed *owner;
/**
+ * User defined data.
+ */
+ void *data;
+
+ /**
* Constructor of the EventHandlerDescriptor struct.
*
* @param type is the event type for which the handler is registered.
@@ -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)
{
}
};