cppexpose  1.0.0.b785e04f23b8
C++ library for type introspection, reflection, and scripting interface
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cppexpose::Signal< Arguments > Class Template Reference

Signal class for communicating events. More...

#include <cppexpose/include/cppexpose/signal/Signal.h>

Inheritance diagram for cppexpose::Signal< Arguments >:
Inheritance graph
[legend]
Collaboration diagram for cppexpose::Signal< Arguments >:
Collaboration graph
[legend]

Public Types

using Callback = std::function< void(Arguments...)>
 Signature for callbacks. More...
 

Public Member Functions

 Signal ()
 Constructor. More...
 
void operator() (Arguments...arguments)
 Emit signal. More...
 
Connection connect (Callback callback) const
 Connect signal to callback function. More...
 
template<class T , class U >
Connection connect (T *object, void(U::*method)(Arguments...)) const
 Connect signal to member function of an object. More...
 
Connection connect (Signal &signal) const
 Connect signal to another signal. More...
 
Connection onFire (std::function< void()> callback) const
 Connect to when the signal is emitted. More...
 
void block ()
 Block signal. More...
 
void unblock ()
 Unblock signal. More...
 
- Public Member Functions inherited from cppexpose::AbstractSignal
 AbstractSignal ()
 Constructor. More...
 
virtual ~AbstractSignal ()
 Destructor. More...
 

Protected Member Functions

void fire (Arguments...arguments) const
 Emit signal. More...
 
virtual void disconnectId (Connection::Id id) const override
 Disconnect connection by ID. More...
 
- Protected Member Functions inherited from cppexpose::AbstractSignal
Connection createConnection () const
 Create new empty connection. More...
 
void disconnect (Connection &connection) const
 Disconnect connection. More...
 

Protected Attributes

std::unordered_map< Connection::Id, Callbackm_callbacks
 List of registered callbacks. More...
 
bool m_blocked
 If 'true', the signal does not emit when invoked. More...
 
- Protected Attributes inherited from cppexpose::AbstractSignal
Connection::Id m_nextId
 Next free connection ID. More...
 
std::unordered_map< Connection::Id, Connectionm_connections
 Map of connections by ID. More...
 

Detailed Description

template<typename... Arguments>
class cppexpose::Signal< Arguments >

Signal class for communicating events.

Member Typedef Documentation

template<typename... Arguments>
using cppexpose::Signal< Arguments >::Callback = std::function<void(Arguments...)>

Signature for callbacks.

Constructor & Destructor Documentation

template<typename... Arguments>
cppexpose::Signal< Arguments >::Signal ( )

Constructor.

Member Function Documentation

template<typename... Arguments>
void cppexpose::Signal< Arguments >::operator() ( Arguments...  arguments)

Emit signal.

Parameters
[in]argumentsSignal arguments

References cppexpose::Signal< Arguments >::fire().

template<typename... Arguments>
Connection cppexpose::Signal< Arguments >::connect ( Callback  callback) const

Connect signal to callback function.

Parameters
[in]callbackCallback function that is invoked

References cppexpose::AbstractSignal::createConnection(), cppexpose::Connection::id(), and cppexpose::Signal< Arguments >::m_callbacks.

Referenced by cppexpose::Signal< Arguments >::connect(), and cppexpose::Signal< Arguments >::onFire().

template<typename... Arguments>
template<class T , class U >
Connection cppexpose::Signal< Arguments >::connect ( T *  object,
void(U::*)(Arguments...)  method 
) const

Connect signal to member function of an object.

Parameters
[in]objectObject
[in]methodMember function that is invoked

References cppexpose::Signal< Arguments >::connect().

template<typename... Arguments>
Connection cppexpose::Signal< Arguments >::connect ( Signal< Arguments > &  signal) const

Connect signal to another signal.

Parameters
[in]signalSignal that is invoked

References cppexpose::Signal< Arguments >::connect().

template<typename... Arguments>
Connection cppexpose::Signal< Arguments >::onFire ( std::function< void()>  callback) const

Connect to when the signal is emitted.

Parameters
[in]callbackCallback function that is invoked
Remarks
This function can be used to connect a callback function to when the signal is emitted. It will be invoked just as a normal callback function, but does not contain the data of the signal.

References cppexpose::Signal< Arguments >::connect().

template<typename... Arguments>
void cppexpose::Signal< Arguments >::block ( )

Block signal.

Remarks
As long as the signal is blocked, it does not emit even if invoked

References cppexpose::Signal< Arguments >::m_blocked.

template<typename... Arguments>
void cppexpose::Signal< Arguments >::unblock ( )

Unblock signal.

References cppexpose::Signal< Arguments >::m_blocked.

template<typename... Arguments>
void cppexpose::Signal< Arguments >::fire ( Arguments...  arguments) const
protected
template<typename... Arguments>
void cppexpose::Signal< Arguments >::disconnectId ( Connection::Id  id) const
overrideprotectedvirtual

Disconnect connection by ID.

Parameters
[in]idConnection ID

Implements cppexpose::AbstractSignal.

References cppexpose::Signal< Arguments >::m_callbacks.

Member Data Documentation

template<typename... Arguments>
std::unordered_map<Connection::Id, Callback> cppexpose::Signal< Arguments >::m_callbacks
mutableprotected
template<typename... Arguments>
bool cppexpose::Signal< Arguments >::m_blocked
protected

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