Leviathan  0.8.0.0
Leviathan game engine
DelegateSlot.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "DelegateSlot.h"
3 
4 
5 using namespace Leviathan;
6 // ------------------------------------ //
7 
8 
10 
12 {
13 
14  // Allow having pointers to delegates from application, but give errors if used as a value
15  // and a script keeps a handle around
16  LEVIATHAN_ASSERT(GetRefCount() == 1 || GetRefCount() == 0,
17  "Delegate still has active references, scripts "
18  "shouldn't store these");
19 }
20 // ------------------------------------ //
21 DLLEXPORT void Delegate::Call(const NamedVars::pointer& values) const
22 {
23 
24  GUARD_LOCK();
25 
26  for(const auto& callback : AttachedCallbacks)
27  callback->OnCalled(values);
28 }
29 
30 DLLEXPORT void Delegate::Call(NamedVars* values) const
31 {
32 
33  GUARD_LOCK();
34 
35  for(const auto& callback : AttachedCallbacks)
36  callback->OnCalled(values);
37 
38  values->Release();
39 }
40 // ------------------------------------ //
41 DLLEXPORT void Delegate::Register(const BaseDelegateSlot::pointer& callback)
42 {
43 
44  GUARD_LOCK();
45 
46  AttachedCallbacks.push_back(callback);
47 }
48 // ------------------------------------ //
49 // LambdaDelegateSlot
DLLEXPORT Delegate()
Definition: DelegateSlot.cpp:9
int32_t GetRefCount() const
Returns the reference count.
FORCE_INLINE void Release()
removes a reference and deletes the object if reference count reaches zero
DLLEXPORT ~Delegate()
DLLEXPORT void Register(const BaseDelegateSlot::pointer &callback)
Registers a new callback.
#define DLLEXPORT
Definition: Include.h:115
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT void Call(const NamedVars::pointer &values) const
Calls all the attached delegates.
#define GUARD_LOCK()
Definition: ThreadSafe.h:97