Leviathan  0.8.0.0
Leviathan game engine
DelegateSlot.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2017 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
8 
9 #include <functional>
10 
11 namespace Leviathan{
12 
15 public:
16 
18  virtual void OnCalled(const NamedVars::pointer &values) = 0;
19 
21 };
22 
24 public:
25 
26  void OnCalled(const NamedVars::pointer &values) override{
27  Callback(values);
28  }
29 
30 protected:
31  // These are protected for only constructing properly reference
32  // counted instances through MakeShared
34 
35  LambdaDelegateSlot(std::function<void(const NamedVars::pointer &values)> callback) :
36  Callback(callback){
37 
38  }
39 
40 private:
41 
42  std::function<void (const NamedVars::pointer &values)> Callback;
43 };
44 
45 
52 class Delegate : public ThreadSafe, public ReferenceCounted{
53 public:
54 
57 
63  DLLEXPORT void Call(const NamedVars::pointer &values) const;
64 
66  DLLEXPORT void Register(const BaseDelegateSlot::pointer &callback);
67 
70  DLLEXPORT void Call(NamedVars* variables) const;
71 
73 
74 private:
75 
76  std::vector<BaseDelegateSlot::pointer> AttachedCallbacks;
77 };
78 
79 
80 }
virtual void OnCalled(const NamedVars::pointer &values)=0
Called from Delegate::Call.
DLLEXPORT Delegate()
Definition: DelegateSlot.cpp:9
Base class for all delegate types.
Definition: DelegateSlot.h:14
Allows the inherited object to be locked.
Definition: ThreadSafe.h:123
REFERENCE_COUNTED_PTR_TYPE(BaseDelegateSlot)
An object which can accept BaseDelegateSlot derived callbacks that can be called when the event repre...
Definition: DelegateSlot.h:52
void OnCalled(const NamedVars::pointer &values) override
Called from Delegate::Call.
Definition: DelegateSlot.h:26
DLLEXPORT ~Delegate()
REFERENCE_COUNTED_PTR_TYPE(Delegate)
DLLEXPORT void Register(const BaseDelegateSlot::pointer &callback)
Registers a new callback.
#define DLLEXPORT
Definition: Include.h:115
LambdaDelegateSlot(std::function< void(const NamedVars::pointer &values)> callback)
Definition: DelegateSlot.h:35
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.