DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
DotNetDupe::System::EventHandler< TEventArgs > Class Template Reference

Represents the method that will handle an event when the event provides data. More...

#include <EventHandler.h>

Public Member Functions

 EventHandler ()
 Initializes a new empty multicast EventHandler instance.
 EventHandler (const EventHandler &other)
 Copy constructor. Copies all subscriber callbacks.
 EventHandler (EventHandler &&other) noexcept
 Move constructor. Transfers subscriber callbacks.
 ~EventHandler ()=default
 Destructor.
size_t Add (const Action< const void *, const TEventArgs & > &fnHandler)
 Subscribes an Action delegate handler and returns a monotonic subscription token.
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, EventHandler> && !std::is_same_v<std::decay_t<F>, Action<const void*, const TEventArgs&>> && std::is_invocable_v<std::decay_t<F>, const void*, const TEventArgs&>>>
size_t Add (F &&fnHandler)
 Subscribes a generic callable object (lambda or function pointer).
template<typename TClass>
size_t Add (TClass *pInstance, void(TClass::*pMethod)(const void *, const TEventArgs &))
 Subscribes a member method on an instance object.
void Clear ()
 Removes all registered subscribers.
size_t GetSubscriberCount () const
 Gets the number of currently active subscribers.
void Invoke (const void *pSender, const TEventArgs &e) const
 Sequentially invokes all registered subscriber callbacks in FIFO order.
bool IsEmpty () const
 Checks whether the multicast event handler has zero registered subscribers.
 operator bool () const
 Boolean conversion operator. Returns true if there are registered subscribers.
void operator() (const void *pSender, const TEventArgs &e) const
 Invocation call operator.
size_t operator+= (const Action< const void *, const TEventArgs & > &fnHandler)
 Multicast addition operator. Subscribes an Action callback.
EventHandleroperator+= (const EventHandler &other)
 Multicast addition operator. Appends all subscribers from another EventHandler.
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, EventHandler> && !std::is_same_v<std::decay_t<F>, Action<const void*, const TEventArgs&>> && std::is_invocable_v<std::decay_t<F>, const void*, const TEventArgs&>>>
size_t operator+= (F &&fnHandler)
 Multicast addition operator. Subscribes a generic callable object.
bool operator-= (size_t nToken)
 Multicast subtraction operator. Unsubscribes using a subscription token.
EventHandleroperator= (const EventHandler &other)
 Copy assignment operator.
EventHandleroperator= (EventHandler &&other) noexcept
 Move assignment operator.
bool Remove (size_t nToken)
 Unsubscribes a subscriber matching the specified subscription token.

Detailed Description

template<typename TEventArgs = EventArgs>
class DotNetDupe::System::EventHandler< TEventArgs >

Represents the method that will handle an event when the event provides data.

Template Parameters
TEventArgsThe type of the event data generated by the event. Defaults to EventArgs.
Note
Conforms to ECMA-335 Partition IV Section 5.22 (System.EventHandler<TEventArgs>). Implements the idiomatic C# publisher-subscriber model with multicast chaining (+=, Add), member method binding (Add(pInstance, &Class::Method)), token-based unsubscription (-=, Remove), and sequential invocation (Invoke, operator()).

Definition at line 27 of file EventHandler.h.

Constructor & Destructor Documentation

◆ EventHandler() [1/3]

template<typename TEventArgs = EventArgs>
DotNetDupe::System::EventHandler< TEventArgs >::EventHandler ( )
inline

Initializes a new empty multicast EventHandler instance.

Definition at line 47 of file EventHandler.h.

Referenced by EventHandler(), EventHandler(), operator+=(), operator=(), and operator=().

◆ EventHandler() [2/3]

template<typename TEventArgs = EventArgs>
DotNetDupe::System::EventHandler< TEventArgs >::EventHandler ( const EventHandler< TEventArgs > & other)
inline

Copy constructor. Copies all subscriber callbacks.

Definition at line 50 of file EventHandler.h.

References EventHandler().

◆ EventHandler() [3/3]

template<typename TEventArgs = EventArgs>
DotNetDupe::System::EventHandler< TEventArgs >::EventHandler ( EventHandler< TEventArgs > && other)
inlinenoexcept

Move constructor. Transfers subscriber callbacks.

Definition at line 54 of file EventHandler.h.

References EventHandler().

◆ ~EventHandler()

template<typename TEventArgs = EventArgs>
DotNetDupe::System::EventHandler< TEventArgs >::~EventHandler ( )
default

Destructor.

Member Function Documentation

◆ Add() [1/3]

template<typename TEventArgs = EventArgs>
size_t DotNetDupe::System::EventHandler< TEventArgs >::Add ( const Action< const void *, const TEventArgs & > & fnHandler)
inline

Subscribes an Action delegate handler and returns a monotonic subscription token.

Parameters
fnHandlerThe delegate to invoke on event dispatch.
Returns
A unique subscription token used to unsubscribe.

Assign monotonic unique subscription token.

Append subscriber to registration list.

Definition at line 84 of file EventHandler.h.

Referenced by Add(), Add(), operator+=(), operator+=(), and operator+=().

◆ Add() [2/3]

template<typename TEventArgs = EventArgs>
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, EventHandler> && !std::is_same_v<std::decay_t<F>, Action<const void*, const TEventArgs&>> && std::is_invocable_v<std::decay_t<F>, const void*, const TEventArgs&>>>
size_t DotNetDupe::System::EventHandler< TEventArgs >::Add ( F && fnHandler)
inline

Subscribes a generic callable object (lambda or function pointer).

Definition at line 95 of file EventHandler.h.

References Add().

◆ Add() [3/3]

template<typename TEventArgs = EventArgs>
template<typename TClass>
size_t DotNetDupe::System::EventHandler< TEventArgs >::Add ( TClass * pInstance,
void(TClass::* pMethod )(const void *, const TEventArgs &) )
inline

Subscribes a member method on an instance object.

Definition at line 101 of file EventHandler.h.

References Add().

◆ Clear()

template<typename TEventArgs = EventArgs>
void DotNetDupe::System::EventHandler< TEventArgs >::Clear ( )
inline

Removes all registered subscribers.

Definition at line 149 of file EventHandler.h.

◆ GetSubscriberCount()

template<typename TEventArgs = EventArgs>
size_t DotNetDupe::System::EventHandler< TEventArgs >::GetSubscriberCount ( ) const
inline

Gets the number of currently active subscribers.

Definition at line 175 of file EventHandler.h.

◆ Invoke()

template<typename TEventArgs = EventArgs>
void DotNetDupe::System::EventHandler< TEventArgs >::Invoke ( const void * pSender,
const TEventArgs & e ) const
inline

Sequentially invokes all registered subscriber callbacks in FIFO order.

Parameters
pSenderPointer to the source object initiating the event.
eThe event data payload.

Sequential multicast dispatch to all registered callbacks.

Definition at line 156 of file EventHandler.h.

Referenced by operator()().

◆ IsEmpty()

template<typename TEventArgs = EventArgs>
bool DotNetDupe::System::EventHandler< TEventArgs >::IsEmpty ( ) const
inline

Checks whether the multicast event handler has zero registered subscribers.

Definition at line 170 of file EventHandler.h.

Referenced by operator bool().

◆ operator bool()

template<typename TEventArgs = EventArgs>
DotNetDupe::System::EventHandler< TEventArgs >::operator bool ( ) const
inlineexplicit

Boolean conversion operator. Returns true if there are registered subscribers.

Definition at line 180 of file EventHandler.h.

References IsEmpty().

◆ operator()()

template<typename TEventArgs = EventArgs>
void DotNetDupe::System::EventHandler< TEventArgs >::operator() ( const void * pSender,
const TEventArgs & e ) const
inline

Invocation call operator.

Definition at line 165 of file EventHandler.h.

References Invoke().

◆ operator+=() [1/3]

template<typename TEventArgs = EventArgs>
size_t DotNetDupe::System::EventHandler< TEventArgs >::operator+= ( const Action< const void *, const TEventArgs & > & fnHandler)
inline

Multicast addition operator. Subscribes an Action callback.

Definition at line 110 of file EventHandler.h.

References Add().

◆ operator+=() [2/3]

template<typename TEventArgs = EventArgs>
EventHandler & DotNetDupe::System::EventHandler< TEventArgs >::operator+= ( const EventHandler< TEventArgs > & other)
inline

Multicast addition operator. Appends all subscribers from another EventHandler.

Definition at line 121 of file EventHandler.h.

References EventHandler(), Add(), and DotNetDupe::System::Collections::Generic::List< T >::GetCount().

◆ operator+=() [3/3]

template<typename TEventArgs = EventArgs>
template<typename F, typename = std::enable_if_t<!std::is_same_v<std::decay_t<F>, EventHandler> && !std::is_same_v<std::decay_t<F>, Action<const void*, const TEventArgs&>> && std::is_invocable_v<std::decay_t<F>, const void*, const TEventArgs&>>>
size_t DotNetDupe::System::EventHandler< TEventArgs >::operator+= ( F && fnHandler)
inline

Multicast addition operator. Subscribes a generic callable object.

Definition at line 116 of file EventHandler.h.

References Add().

◆ operator-=()

template<typename TEventArgs = EventArgs>
bool DotNetDupe::System::EventHandler< TEventArgs >::operator-= ( size_t nToken)
inline

Multicast subtraction operator. Unsubscribes using a subscription token.

Definition at line 144 of file EventHandler.h.

References Remove().

◆ operator=() [1/2]

template<typename TEventArgs = EventArgs>
EventHandler & DotNetDupe::System::EventHandler< TEventArgs >::operator= ( const EventHandler< TEventArgs > & other)
inline

Copy assignment operator.

Definition at line 60 of file EventHandler.h.

References EventHandler().

◆ operator=() [2/2]

template<typename TEventArgs = EventArgs>
EventHandler & DotNetDupe::System::EventHandler< TEventArgs >::operator= ( EventHandler< TEventArgs > && other)
inlinenoexcept

Move assignment operator.

Definition at line 69 of file EventHandler.h.

References EventHandler().

◆ Remove()

template<typename TEventArgs = EventArgs>
bool DotNetDupe::System::EventHandler< TEventArgs >::Remove ( size_t nToken)
inline

Unsubscribes a subscriber matching the specified subscription token.

Parameters
nTokenThe subscription token returned from Add.
Returns
true if a subscriber was found and removed; otherwise, false.

Linearly search registry for matching subscription token.

Definition at line 132 of file EventHandler.h.

Referenced by operator-=().


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