EasyDelegate  2.0
Delegate and deferred callers for C++11.
Public Types | Public Member Functions | List of all members
EasyDelegate::DelegateSet< returnType, parameters > Class Template Reference

A set of delegate instances that provides helper methods to invoke all contained delegates. More...

#include <delegateset.hpp>

Inheritance diagram for EasyDelegate::DelegateSet< returnType, parameters >:

Public Types

typedef returnType(* delegateFuncPtr) (parameters...)
 Helper typedef to construct the function pointer signature from the template.
 
typedef StaticDelegate< returnType, parameters...> StaticDelegateType
 Helper typedef for when building static delegates for this set.
 
template<typename classType >
using MemberDelegateType = MemberDelegate< classType, returnType, parameters...>
 Helper typedef for when building member delegates for this set.
 
typedef returnType ReturnType
 Helper typedef for when wanting the return type of this set.
 
typedef ITypedDelegate< returnType, parameters...> StoredDelegateType
 Helper typedef to construct the StaticDelegate signature from the template.
 
typedef returnType(* StaticDelegateFuncPtr) (parameters...)
 Helper typedef referring to a static function pointer.
 
template<typename classType >
using MemberDelegateFuncPtr = returnType(classType::*)(parameters...)
 Helper typedef referring to a member function pointer.
 
template<typename classType >
using DeferredMemberCallerType = DeferredMemberCaller< classType, returnType, parameters...>
 A helper typedef to a DeferredMemberCaller that works against the specified class and matches the signatures stored in this delegate set.
 
typedef DeferredStaticCaller< returnType, parameters...> DeferredStaticCallerType
 A helper typedef to a DeferredStaticCaller matches the signatures stored in this delegate set.
 
typedef std::set< returnType > ReturnSetType
 Helper typedef to an std::set that is compatible with the return types of delegates stored here.
 

Public Member Functions

 ~DelegateSet (void)
 Standard destructor.
 
EASYDELEGATE_INLINE void invoke (parameters...params) const
 Invoke all delegates in the set, ignoring return values. More...
 
EASYDELEGATE_INLINE void invoke (std::set< returnType > &out, parameters...params) const
 Invoke all delegates in the set, storing return values in out. More...
 
EASYDELEGATE_INLINE void push_back (StoredDelegateType *delegateInstance)
 Pushes a delegate instance to the end of the set. More...
 
EASYDELEGATE_INLINE void operator+= (StoredDelegateType *delegateInstance)
 Pushes a delegate instance to the end of the set. More...
 
template<typename className >
EASYDELEGATE_INLINE void removeDelegateByMethod (const MemberDelegateFuncPtr< className > method, const bool &deleteInstances=true, std::unordered_set< StoredDelegateType * > *out=NULL)
 Removes all delegates from the set that have the given class member method address for its method. More...
 
void removeDelegateByMethod (StaticDelegateFuncPtr methodPointer, const bool &deleteInstances=true, std::unordered_set< StoredDelegateType * > *out=NULL)
 Removes all delegates from the set that have the given static method address for it's method. More...
 
void removeDelegateByThisPointer (const void *thisPtr, const bool &deleteInstances=true, std::unordered_set< StoredDelegateType * > *out=NULL)
 Removes a all MemberDelegate types from the set that have a given 'this' pointer address to call against. More...
 
StoredDelegateTyperemoveDelegate (StoredDelegateType *instance, const bool &deleteInstance=true)
 Removes a given delegate by its address. More...
 

Detailed Description

template<typename returnType, typename... parameters>
class EasyDelegate::DelegateSet< returnType, parameters >

A set of delegate instances that provides helper methods to invoke all contained delegates.

The DelegateSet type can be described as a sink for specific event types. Typical usage of this behavior would involve creating a typedef of a DelegateSet type for a specific method signature which then has its own specialized typedefs to facilitate the creation of StaticDelegate and MemberDelegate types that are compatible with instances of this new specialized DelegateSet type.

Examples:
example.cpp.

Member Function Documentation

template<typename returnType , typename... parameters>
EASYDELEGATE_INLINE void EasyDelegate::DelegateSet< returnType, parameters >::invoke ( parameters...  params) const
inline

Invoke all delegates in the set, ignoring return values.

Parameters
paramsAll other arguments that will be used as parameters to each delegate.
Exceptions
InvalidMethodPointerExceptionThrown when assertions are disabled and either a stored MemberDelegate or StaticDelegate type have a NULL function to call.
InvalidThisPointerExceptionThrown when assertions are disabled and a stored MemberDelegate is attempting to call against a NULL this pointer.
std::exceptionAny exception can be potentially thrown by the functions each delegate calls.
Note
The call will not throw an exception in any of the DelegateException cases but rather assert if assertions are enabled.
If this throws an exception, the invocation of the set halts.
template<typename returnType , typename... parameters>
EASYDELEGATE_INLINE void EasyDelegate::DelegateSet< returnType, parameters >::invoke ( std::set< returnType > &  out,
parameters...  params 
) const
inline

Invoke all delegates in the set, storing return values in out.

Parameters
outThe std::set that all return values will be sequentially written to.
paramsAll other arguments that will be used as parameters to each delegate.
Exceptions
InvalidMethodPointerExceptionThrown when assertions are disabled and either a stored MemberDelegate or StaticDelegate type have a NULL function to call.
InvalidThisPointerExceptionThrown when assertions are disabled and a stored MemberDelegate is attempting to call against a NULL this pointer.
std::exceptionAny exception can be potentially thrown by the functions each delegate calls.
Note
The call will not throw an exception in any of the DelegateException cases but rather assert if assertions are enabled.
If this throws an exception, the invocation of the set halts.
template<typename returnType , typename... parameters>
EASYDELEGATE_INLINE void EasyDelegate::DelegateSet< returnType, parameters >::operator+= ( StoredDelegateType delegateInstance)
inline

Pushes a delegate instance to the end of the set.

Parameters
delegateInstanceThe delegate instance to the pushed onto the set.
Warning
Ownership of the delegate will be given to the set, therefore the given delegate should not be deleted manually.
template<typename returnType , typename... parameters>
EASYDELEGATE_INLINE void EasyDelegate::DelegateSet< returnType, parameters >::push_back ( StoredDelegateType delegateInstance)
inline

Pushes a delegate instance to the end of the set.

Parameters
delegateInstanceThe delegate instance to the pushed onto the set.
Warning
Ownership of the delegate will be given to the set, therefore the given delegate should not be deleted manually.
template<typename returnType , typename... parameters>
StoredDelegateType* EasyDelegate::DelegateSet< returnType, parameters >::removeDelegate ( StoredDelegateType instance,
const bool &  deleteInstance = true 
)
inline

Removes a given delegate by its address.

Parameters
instanceThe delegate pointer to attempt to remove from this set.
deleteInstanceA boolean representing whether or not the target delegate should be deleted.
Returns
A pointer to the delegate that was removed. This is NULL if none were removed or if deleteInstance is true.
template<typename returnType , typename... parameters>
template<typename className >
EASYDELEGATE_INLINE void EasyDelegate::DelegateSet< returnType, parameters >::removeDelegateByMethod ( const MemberDelegateFuncPtr< className >  method,
const bool &  deleteInstances = true,
std::unordered_set< StoredDelegateType * > *  out = NULL 
)
inline

Removes all delegates from the set that have the given class member method address for its method.

Parameters
methodThe class method method poiner to check against.
deleteInstancesA boolean representing whether or not all matches should be deleted when removed. The default for this parameter is true for better memory management.
outA pointer to an std::unordered_set templated for the ITypedDelegate type that this DelegateSet contains. This set will then be populated with a list of removed delegates if deleteInstances if false. If deleteInstances is true, this list will never be populated as the removed delegates are simply deleted.
Warning
If deleteInstances=false, then the delegates written to out will have their ownership transferred to whatever made the call, so they must be deletated accordingly.
template<typename returnType , typename... parameters>
void EasyDelegate::DelegateSet< returnType, parameters >::removeDelegateByMethod ( StaticDelegateFuncPtr  methodPointer,
const bool &  deleteInstances = true,
std::unordered_set< StoredDelegateType * > *  out = NULL 
)
inline

Removes all delegates from the set that have the given static method address for it's method.

Parameters
methodPointerThe static method pointer to check against.
deleteInstancesA boolean representing whether or not all matches should be deleted when removed. The default for this parameter is true for better memory management.
outA pointer to an std::unordered_set templated for the ITypedDelegate type that this DelegateSet contains. This set will then be populated with a list of removed delegates if deleteInstances is false. If deleteInstances is true, then this list will never be populated as the removed delegates are simply destroyed.
Warning
If deleteInstances is false and there is no out specified, you will be leaking memory if there is no other delegate sets tracking the removed delegates.
template<typename returnType , typename... parameters>
void EasyDelegate::DelegateSet< returnType, parameters >::removeDelegateByThisPointer ( const void *  thisPtr,
const bool &  deleteInstances = true,
std::unordered_set< StoredDelegateType * > *  out = NULL 
)
inline

Removes a all MemberDelegate types from the set that have a given 'this' pointer address to call against.

Parameters
thisPtrThe address of the object to check against.
deleteInstancesA boolean representing whether or not all matches should be deleted when removed. The default for this parameter is true for better memory management.
outA pointer to an std::unordered_set templated for the ITypedDelegate type that this DelegateSet contains. This set will then be populated with a list of removed delegates if deleteInstances is false. If deleteInstances is true, then this list will never be populated as the removed delegates are simply deleted.
Warning
If deleteInstances is false and there is no out specified, you will be leaking memory if there is no other delegate set tracking the removed delegates.

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