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

Represents signal. More...

#include <Signal.hpp>

Classes

class  Receiver
 

Public Types

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

Public Member Functions

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

Detailed Description

template<typename S>
class CppMate::Signal< S >

Represents signal.

Member Typedef Documentation

◆ Function

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

Signature of signal receiver function.

◆ Lambda

template<typename S >
using CppMate::Signal< S >::Lambda = std::function<void(const S& sender)>

Lambda type of the signal receiver.

Constructor & Destructor Documentation

◆ Signal()

template<typename S >
CppMate::Signal< S >::Signal ( const S &  sender)
inline

Constructor.

Parameters
senderthe instance of signal sender.

Member Function Documentation

◆ emit()

template<typename S >
void CppMate::Signal< S >::emit ( )
inline

Emits signal.

◆ getSubscribersCount()

template<typename S >
size_t CppMate::Signal< S >::getSubscribersCount ( ) const
inline

Returns number of recveivers.

Returns
number of recveivers.

◆ hasSubscriber() [1/3]

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

Indicates that the receiver is already subscribed to the signal.

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

◆ hasSubscriber() [2/3]

template<typename S >
bool CppMate::Signal< S >::hasSubscriber ( Function  subscriber) const
inline

Indicates that the receiver is already subscribed to the signal.

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

◆ hasSubscriber() [3/3]

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

Indicates that the receiver is already subscribed to the signal.

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

◆ isEmpty()

template<typename S >
bool CppMate::Signal< S >::isEmpty ( ) const
inline

Indicates that subsciprion is empty.

Returns
true if subscription list is empty; false otherwise.

◆ subscribe() [1/4]

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

Subscribes method of instance to the signal. The subscription is unique.

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

◆ subscribe() [2/4]

template<typename S >
void CppMate::Signal< S >::subscribe ( Function  subscriber) const
inline

Subscribes function to the signal.

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

◆ subscribe() [3/4]

template<typename S >
void CppMate::Signal< S >::subscribe ( Lambda  subscriber) const
inline

Subscribes lambda expression to the signal.

Parameters
subscriberthe subscriber.

◆ subscribe() [4/4]

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

Subscribes method of instance to the signal. 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).
Exceptions
std::invalid_argument

◆ unsubscribe() [1/3]

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

Unsubscribes from the signal.

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

◆ unsubscribe() [2/3]

template<typename S >
bool CppMate::Signal< S >::unsubscribe ( Function  subscriber) const
inline

Unsubscribes function from the signal.

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

◆ unsubscribe() [3/3]

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

Unsubscribes from the signal.

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 S >
void CppMate::Signal< S >::unsubscribeAll ( )
inline

Clear all subscribers.


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