cpp-mate  0.7
Helpful library for C++.
CppMate::Event< E, S > Class Template Referencefinal

Represents signal emitter with a specified event type. More...

#include <Event.hpp>

Classes

class  Receiver
 

Public Types

using Function = void(*)(const S &, const E &)
 
using Lambda = std::function< void(const S &sender, const E &event)>
 

Public Member Functions

 Event (const S &sender)
 Constructor. More...
 
template<typename T >
void subscribe (const T &instance, void(T::*method)(const S &, const E &)) const
 Subscribes method of instance to the event passed by constant reference. The subscription is unique. More...
 
template<typename T >
void subscribe (std::shared_ptr< T > instance, void(T::*method)(const S &, const E &)) const
 Subscribes method of instance to the event passed by constant reference. The subscription is unique. More...
 
void subscribe (Function subscriber) const
 Subscribes function to the event. More...
 
void subscribe (Lambda subscriber) const
 Subscribes lambda expression to the event. More...
 
template<typename T >
bool unsubscribe (const T &instance, void(T::*method)(const S &, const E &)) const
 Unsubscribes from the event. More...
 
template<typename T >
bool unsubscribe (std::shared_ptr< T > instance, void(T::*method)(const S &, const E &)) const
 Unsubscribes from the event. More...
 
bool unsubscribe (Function subscriber) const
 Unsubscribes from the event. More...
 
template<typename T >
bool hasSubscriber (const T &instance, void(T::*method)(const S &, const E &)) const
 Indicates that the receiver is already subscribed to the event. More...
 
template<typename T >
bool hasSubscriber (std::shared_ptr< T > instance, void(T::*method)(const S &, const E &)) const
 Indicates that the receiver is already subscribed to the event. More...
 
bool hasSubscriber (Function subscriber) const
 Indicates that the receiver is already subscribed to the event. More...
 
bool isEmpty () const
 Indicates that subsciprion is empty. More...
 
size_t getSubscribersCount () const
 Returns number of recveivers. More...
 
void emit (const E &event)
 Emits event. More...
 
void unsubscribeAll ()
 Clear all subscribers. More...
 

Detailed Description

template<typename E, typename S>
class CppMate::Event< E, S >

Represents signal emitter with a specified event type.

Member Typedef Documentation

◆ Function

template<typename E , typename S >
using CppMate::Event< E, S >::Function = void(*)(const S&, const E&)

Signature of event receiver function.

◆ Lambda

template<typename E , typename S >
using CppMate::Event< E, S >::Lambda = std::function<void(const S& sender, const E& event)>

Lambda type of the event receiver.

Constructor & Destructor Documentation

◆ Event()

template<typename E , typename S >
CppMate::Event< E, S >::Event ( const S &  sender)
inline

Constructor.

Parameters
senderthe instance of signal sender.

Member Function Documentation

◆ emit()

template<typename E , typename S >
void CppMate::Event< E, S >::emit ( const E &  event)
inline

Emits event.

Parameters
eventthe event to emit.

◆ getSubscribersCount()

template<typename E , typename S >
size_t CppMate::Event< E, S >::getSubscribersCount ( ) const
inline

Returns number of recveivers.

Returns
number of recveivers.

◆ hasSubscriber() [1/3]

template<typename E , typename S >
template<typename T >
bool CppMate::Event< E, S >::hasSubscriber ( const T &  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Indicates that the receiver is already subscribed to the event.

Parameters
instancethe class instance.
methodthe class method.
Returns
true if receiver is subcribed; false otherwise.

◆ hasSubscriber() [2/3]

template<typename E , typename S >
bool CppMate::Event< E, S >::hasSubscriber ( Function  subscriber) const
inline

Indicates that the receiver is already subscribed to the event.

Parameters
subscriberthe receiver function.
Returns
true if receiver is subcribed; false otherwise.

◆ hasSubscriber() [3/3]

template<typename E , typename S >
template<typename T >
bool CppMate::Event< E, S >::hasSubscriber ( std::shared_ptr< T >  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Indicates that the receiver is already subscribed to the event.

Parameters
instancethe shared pointer to class instance.
methodthe class method.
Returns
true if receiver is subcribed; false otherwise.

◆ isEmpty()

template<typename E , typename S >
bool CppMate::Event< E, S >::isEmpty ( ) const
inline

Indicates that subsciprion is empty.

Returns
true if subscription list is empty; false otherwise.

◆ subscribe() [1/4]

template<typename E , typename S >
template<typename T >
void CppMate::Event< E, S >::subscribe ( const T &  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Subscribes method of instance to the event passed by constant reference. The subscription is unique.

Parameters
instancethe class instance.
methodthe class method.
Note
Signature of method should be: void receiver(const S& sender, const E& event).

◆ subscribe() [2/4]

template<typename E , typename S >
void CppMate::Event< E, S >::subscribe ( Function  subscriber) const
inline

Subscribes function to the event.

Parameters
subscriberpointer to a function which receives an event.
Exceptions
std::invalid_argument

◆ subscribe() [3/4]

template<typename E , typename S >
void CppMate::Event< E, S >::subscribe ( Lambda  subscriber) const
inline

Subscribes lambda expression to the event.

Parameters
subscriberthe subscriber.

◆ subscribe() [4/4]

template<typename E , typename S >
template<typename T >
void CppMate::Event< E, S >::subscribe ( std::shared_ptr< T >  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Subscribes method of instance to the event passed by constant reference. The subscription is unique.

Parameters
instancethe shared pointer to class instance.
methodthe class method.
Note
Signature of method should be: void receiver(const S& sender, const E& event).
Exceptions
std::invalid_argument

◆ unsubscribe() [1/3]

template<typename E , typename S >
template<typename T >
bool CppMate::Event< E, S >::unsubscribe ( const T &  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Unsubscribes from the event.

Parameters
instancethe class instance.
methodthe class method.
Returns
true if receiver was removed; false otherwise.

◆ unsubscribe() [2/3]

template<typename E , typename S >
bool CppMate::Event< E, S >::unsubscribe ( Function  subscriber) const
inline

Unsubscribes from the event.

Parameters
subscriberthe receiver function.
Returns
true if receiver was removed; false otherwise.
Exceptions
std::invalid_argument

◆ unsubscribe() [3/3]

template<typename E , typename S >
template<typename T >
bool CppMate::Event< E, S >::unsubscribe ( std::shared_ptr< T >  instance,
void(T::*)(const S &, const E &)  method 
) const
inline

Unsubscribes from the event.

Parameters
instancethe shared pointer to class instance.
methodthe class method.
Returns
true if receiver was removed; false otherwise.
Exceptions
std::invalid_argument

◆ unsubscribeAll()

template<typename E , typename S >
void CppMate::Event< E, S >::unsubscribeAll ( )
inline

Clear all subscribers.


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