DelegateBase Class Reference

#include <delegate.h>

Inheritance diagram for DelegateBase:

Detailed Description

Delegate base class which can be used for DataType.

Public Types

using Stub = void(*)()
 

Public Member Functions

 DelegateBase ()
 
 ~DelegateBase ()
 
template<typename STUBPTR >
 DelegateBase (void *objectPtr, STUBPTR stubPtr, Callback callback)
 
template<typename FN , typename STUBPTR >
 DelegateBase (FN &&fn, STUBPTR stub, Callback callback)
 
 DelegateBase (const DelegateBase &)=delete
 
 DelegateBase (DelegateBase &&src)
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (DelegateBase)
 
void Reset ()
 
ResultMem CopyFrom (const DelegateBase &src)
 
template<typename FN , typename STUBPTR >
ResultMem CopyFrom (FN &&f, STUBPTR stub, Callback callback)
 
template<typename OBJ , typename STUBPTR >
ResultMem CopyFrom (OBJ &&object, STUBPTR stub)
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
Bool IsStaticFunctionPointer () const
 
template<typename FUNCTIONPTR >
FUNCTIONPTR GetStaticFunctionPointer () const
 
template<typename STUBPTR >
STUBPTR GetStubPointer () const
 

Protected Types

enum class  CALLBACKMODE {
  ALLOC ,
  DESTRUCT_AND_RELEASE ,
  COPY ,
  MOVE_AND_DESTRUCT
}
 
using Callback = Int(*)(DelegateBase *dst, const DelegateBase *src, CALLBACKMODE mode)
 

Protected Member Functions

enum maxon::DelegateBase::CALLBACKMODE MAXON_ENUM_ORDERED_LIST_CLASS (CALLBACKMODE)
 

Static Protected Member Functions

template<typename REF >
static Callback GetReferenceUtilityStub (void *)
 
template<typename REF >
static Callback GetReferenceUtilityStub (PointerHandler *)
 
static Int PTMFUtilityStub (DelegateBase *dst, const DelegateBase *src, CALLBACKMODE mode)
 
template<typename T >
static Int UtilityStub (DelegateBase *dst, const DelegateBase *src, CALLBACKMODE mode)
 
template<typename REFERENCE >
static Int ReferenceUtilityStub (DelegateBase *dst, const DelegateBase *src, CALLBACKMODE mode)
 

Protected Attributes

void * _storage [5]
 
void * _objectPtr
 
Stub _stubPtr
 
Callback _callback
 

Member Typedef Documentation

◆ Callback

using Callback = Int (*)(DelegateBase* dst, const DelegateBase* src, CALLBACKMODE mode)
protected

◆ Stub

using Stub = void(*)()

Member Enumeration Documentation

◆ CALLBACKMODE

enum CALLBACKMODE
strongprotected
Enumerator
ALLOC 

Allocates memory for an object.

DESTRUCT_AND_RELEASE 

Destructs the object to which dst points and releases the memory.

COPY 

Copies the object from src to dst and returns the size on success (0 on failure).

MOVE_AND_DESTRUCT 

Moves the object from src to dst and returns the size (only used for internal storage, cannot fail).

Constructor & Destructor Documentation

◆ DelegateBase() [1/5]

◆ ~DelegateBase()

◆ DelegateBase() [2/5]

DelegateBase ( void *  objectPtr,
STUBPTR  stubPtr,
Callback  callback 
)

Constructs a delegate using object, stub and utility callback pointer.

Template Parameters
STUBPTRThe stub pointer type.
Parameters
[in]objectPtrSelf pointer of the object. Might be nullptr if the method has been inlined into the stub.
[in]stubPtrStub method pointer (which forward the call to the callable).
[in]callbackUtility callback which handles copy, move and destruction of the object. Nullptr for a static function.

◆ DelegateBase() [3/5]

DelegateBase ( FN &&  fn,
STUBPTR  stub,
Callback  callback 
)

Assign when T is not a Delegate, but a function pointer, ptmf or a PTMFWrapper<OBJECT*, RESULT (OBJECT::*)(ARGS...)>.

◆ DelegateBase() [4/5]

DelegateBase ( const DelegateBase )
delete

◆ DelegateBase() [5/5]

Member Function Documentation

◆ MAXON_ENUM_ORDERED_LIST_CLASS()

enum maxon::DelegateBase::CALLBACKMODE MAXON_ENUM_ORDERED_LIST_CLASS ( CALLBACKMODE  )
protected

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( DelegateBase  )

◆ Reset()

void Reset ( void  )

◆ CopyFrom() [1/3]

ResultMem CopyFrom ( const DelegateBase src)
Parameters
[in]srcSource delegate.
Returns
OK on success.

◆ CopyFrom() [2/3]

ResultMem CopyFrom ( FN &&  f,
STUBPTR  stub,
Callback  callback 
)

Assign when T is not a Delegate, but a function pointer, ptmf or a PTMFWrapper<OBJECT*, RESULT (OBJECT::*)(ARGS...)>.

◆ CopyFrom() [3/3]

ResultMem CopyFrom ( OBJ &&  object,
STUBPTR  stub 
)

Copies or moves object into the Delegate and sets #stub as the handler for delegate calls. #stub will receive a pointer to the object held by the Delegate in its first parameter.

Parameters
[in]objectThe object to move or copy.
[in]stubThe call handler.
Returns
OK on success.

◆ IsEmpty()

Bool IsEmpty ( ) const

◆ IsPopulated()

Bool IsPopulated ( void  ) const

◆ IsStaticFunctionPointer()

Bool IsStaticFunctionPointer ( ) const

◆ GetStaticFunctionPointer()

FUNCTIONPTR GetStaticFunctionPointer ( ) const

◆ GetStubPointer()

STUBPTR GetStubPointer ( ) const

◆ GetReferenceUtilityStub() [1/2]

static Callback GetReferenceUtilityStub ( void *  )
staticprotected

◆ GetReferenceUtilityStub() [2/2]

static Callback GetReferenceUtilityStub ( PointerHandler )
staticprotected

◆ PTMFUtilityStub()

static Int PTMFUtilityStub ( DelegateBase dst,
const DelegateBase src,
CALLBACKMODE  mode 
)
staticprotected

A dummy stub for inlined PTMF which does nothing.

◆ UtilityStub()

Int UtilityStub ( DelegateBase dst,
const DelegateBase src,
CALLBACKMODE  mode 
)
staticprotected

Destructs, copies or moves an object with operator ()().

◆ ReferenceUtilityStub()

static Int ReferenceUtilityStub ( DelegateBase dst,
const DelegateBase src,
CALLBACKMODE  mode 
)
staticprotected

Destructs, copies or moves a reference with operator ()(). This treats _storage[0] as if it was not just a pointer, but a REFERENCE.

Member Data Documentation

◆ _storage

void* _storage[5]
protected

◆ _objectPtr

void* _objectPtr
protected

◆ _stubPtr

Stub _stubPtr
protected

◆ _callback

Callback _callback
protected