Nebula
Loading...
Searching...
No Matches
delegatetable.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "util/delegate.h"
15#include "messaging/id.h"
16#include "messaging/message.h"
17
18//------------------------------------------------------------------------------
19namespace Messaging
20{
22{
23public:
25 template<class CLASS, void (CLASS::*METHOD)(const Ptr<Message>&)> void Bind(const Id& msgId, CLASS* obj);
27 bool Invoke(const Ptr<Message>& msg);
28
29private:
31 void AddDelegate(const Id& msgId, const Util::Delegate<void(const Ptr<Message>&)>& del);
32
35};
36
37//------------------------------------------------------------------------------
40template<class CLASS, void (CLASS::*METHOD)(const Ptr<Message>&)>
41void
42DelegateTable::Bind(const Id& msgId, CLASS* obj)
43{
44 // setup a new delegate
45 Util::Delegate<void(const Ptr<Message>&)> del = Util::Delegate<void(const Ptr<Message>&)>::FromMethod<CLASS,METHOD>(obj);
46 this->AddDelegate(msgId, del);
47}
48
49} // namespace Messaging
50//------------------------------------------------------------------------------
Associates message ids with handler delegates.
Definition delegatetable.h:22
bool Invoke(const Ptr< Message > &msg)
invoke delegates bound to msg, returns false if no delegates bound to msg id
Definition delegatetable.cc:37
Util::Array< Util::Array< Util::Delegate< void(const Ptr< Message > &)> > > delegateArray
Definition delegatetable.h:33
void Bind(const Id &msgId, CLASS *obj)
bind a message id to a method call
Definition delegatetable.h:42
Util::Dictionary< const Id *, IndexT > idIndexMap
Definition delegatetable.h:34
void AddDelegate(const Id &msgId, const Util::Delegate< void(const Ptr< Message > &)> &del)
add a delegate
Definition delegatetable.cc:17
A message identifier.
Definition id.h:19
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
Nebula delegate class, allows to store a function, method or lambda call into a C++ object for later ...
Definition delegate.h:39
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
Definition asyncport.cc:10