Leviathan game engine
Leviathan::Delegate Class Reference

An object which can accept BaseDelegateSlot derived callbacks that can be called when the event represented by this delegate is called. More...

#include <DelegateSlot.h>

+ Inheritance diagram for Leviathan::Delegate:

Public Member Functions

DLLEXPORT Delegate ()
DLLEXPORT ~Delegate ()
DLLEXPORT void Call (const NamedVars::pointer &values) const
 Calls all the attached delegates. More...
DLLEXPORT void Register (const BaseDelegateSlot::pointer &callback)
 Registers a new callback. More...
DLLEXPORT void Call (NamedVars *variables) const
 AngelScript wrapper for Call. More...
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
DLLEXPORT ~ThreadSafeGeneric ()
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
FORCE_INLINE void VerifyLock (Lock &lockit) const
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
FORCE_INLINE void AddRef () const
FORCE_INLINE void Release () const
 removes a reference and deletes the object if reference count reaches zero More...
FORCE_INLINE void AddRef ()
FORCE_INLINE void Release ()
int32_t GetRefCount () const
 Returns the reference count. More...

Additional Inherited Members

- Public Types inherited from Leviathan::ThreadSafeGeneric< MutexType >
using LockT = typename LockTypeResolver< MutexType >::LType
- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
virtual DLLEXPORT ~ReferenceCounted ()
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock

Detailed Description

An object which can accept BaseDelegateSlot derived callbacks that can be called when the event represented by this delegate is called.

Allow unregistering callbacks
Many objects will have Delegates as their members without pointers so scripts really shouldn't try to store these. unless the specific object supports storing them

Definition at line 52 of file DelegateSlot.h.

Constructor & Destructor Documentation

◆ Delegate()

DLLEXPORT Delegate::Delegate ( )

Definition at line 9 of file DelegateSlot.cpp.

9 {}

◆ ~Delegate()

DLLEXPORT Delegate::~Delegate ( )

Definition at line 11 of file DelegateSlot.cpp.

12 {
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 }
int32_t GetRefCount() const
Returns the reference count.
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:100

Member Function Documentation

◆ Call() [1/2]

DLLEXPORT void Delegate::Call ( const NamedVars::pointer &  values) const

Calls all the attached delegates.

valuesThe data for the callbacks to receive.
Find a way to more efficiently pass known types or data that may not be stored (only copied)

Definition at line 21 of file DelegateSlot.cpp.

22 {
26  for(const auto& callback : AttachedCallbacks)
27  callback->OnCalled(values);
28 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:111

◆ Call() [2/2]

DLLEXPORT void Delegate::Call ( NamedVars variables) const

AngelScript wrapper for Call.

Decreases reference count

Definition at line 30 of file DelegateSlot.cpp.

31 {
35  for(const auto& callback : AttachedCallbacks)
36  callback->OnCalled(values);
38  values->Release();
39 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:111


Leviathan::Delegate::REFERENCE_COUNTED_PTR_TYPE ( Delegate  )

◆ Register()

DLLEXPORT void Delegate::Register ( const BaseDelegateSlot::pointer &  callback)

Registers a new callback.

Definition at line 41 of file DelegateSlot.cpp.

42 {
46  AttachedCallbacks.push_back(callback);
47 }
#define GUARD_LOCK()
Definition: ThreadSafe.h:111

The documentation for this class was generated from the following files: