summaryrefslogtreecommitdiff
path: root/src/core/Node.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-02 16:00:01 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-01-02 16:00:01 +0100
commit128ac91adfdab4a21836c4f19d7024dba9790f9e (patch)
tree20ae14f5c9e2cbd1e2ae6ce37f4fb575c5ea237a /src/core/Node.cpp
parentdd3fccac307527d3b1285f6ac7966b6d527627cb (diff)
Moved event system from the Node class to the Managed class (with zero overhead if is not used)
Diffstat (limited to 'src/core/Node.cpp')
-rw-r--r--src/core/Node.cpp48
1 files changed, 4 insertions, 44 deletions
diff --git a/src/core/Node.cpp b/src/core/Node.cpp
index 665430c..fa6a3a2 100644
--- a/src/core/Node.cpp
+++ b/src/core/Node.cpp
@@ -25,8 +25,10 @@ namespace ousia {
void Node::setName(std::string name)
{
// Call the name change event
- NameChangeEvent ev{this->name, name};
- triggerEvent(ev);
+ {
+ NameChangeEvent ev{this->name, name};
+ triggerEvent(ev);
+ }
// Set the new name
this->name = std::move(name);
@@ -97,48 +99,6 @@ std::vector<Rooted<Managed>> Node::resolve(const std::vector<std::string> &path,
return res;
}
-int Node::registerEventHandler(EventType type, EventHandler handler,
- Handle<Managed> owner,
- bool includeChildren)
-{
- const int id = handlerIdCounter++;
- handlers.insert(std::make_pair(
- type,
- EventHandlerDescriptor{id, handler, owner, this, includeChildren}));
- return id;
-}
-
-bool Node::unregisterEventHandler(int id) {
- for (auto it = handlers.begin(); it != handlers.end(); it++) {
- if (it->second.id == id) {
- handlers.erase(it);
- return true;
- }
- }
- return false;
-}
-
-bool Node::triggerEvent(Event &event, bool fromChild) {
- bool res = false;
- // Iterate over all event handlers
- const auto range = handlers.equal_range(event.type);
- for (auto it = range.first; it != range.second; it++) {
- // Fetch a reference to the descriptor, check whether it should be
- // called for bubbled events
- EventHandlerDescriptor descr = it->second;
- if (!fromChild || descr.includeChildren) {
- descr.handler(event, descr.owner);
- res = true;
- }
- }
-
- // If possible, let the event bubble up to the parent node
- if (event.canBubble() && !parent.isNull()) {
- res = parent->triggerEvent(event, true) | res;
- }
- return res;
-}
-
/* RTTI type registrations */
const Rtti<Node> RttiTypes::Node{"Node"};