Rosetta  2020.37
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
utility::signals::SignalHub< ResultType, Signal > Class Template Reference

forward declaration for SignalHub More...

#include <SignalHub.hh>

Public Types

typedef platform::Size Size
 

Public Member Functions

 SignalHub ()
 default constructor More...
 
virtual ~SignalHub ()
 default destructor More...
 
void operator() (Signal s)
 send signal to all observers connected to the hub More...
 
Size size () const
 number of connections to the hub More...
 
void block ()
 block signals from being sent More...
 
virtual void unblock ()
 allow signals to be sent More...
 
bool blocked () const
 are signals blocked? More...
 
void clear ()
 clear all connections More...
 
template<typename MemFn , typename Ptr >
Link connect (MemFn fn, Ptr ptr)
 connect an observer's member function to this hub More...
 
template<typename MemFn , typename Ptr >
bool disconnect (MemFn fn, Ptr ptr)
 disconnect an observer's member function from this hub More...
 
Size receive_linkunits_from (SignalHub const &src)
 transfer linkunits from source to this SignalHub More...
 
Links current_links () const
 return a copy of the list of links currently being managed by this SignalHub More...
 

Protected Types

typedef boost::function1
< ReturnType, Signal
Function
 
typedef std::vector< LinkUnitOPLinkUnits
 
typedef std::vector< LinkLinks
 

Protected Member Functions

virtual bool signal_allowed (Signal const )
 is signal allowed to be passed? More...
 
virtual void send_signal (Signal s)
 send signal to all observers More...
 
virtual void after_send ()
 initiate an action after send (no-op in SignalHub) More...
 
template<typename MemFn , typename Ptr >
Link connect (MemFn fn, Ptr ptr, LinkUnits &links) const
 connect an observer's member function to the given LinkUnits More...
 
template<typename MemFn , typename Ptr >
bool disconnect (MemFn fn, Ptr ptr, LinkUnits &links) const
 disconnect an observer's member function from the given LinkUnits More...
 
template<typename Functor >
LinkUnits::iterator find_connection (Functor f, LinkUnits &links) const
 find a specific connection to this hub More...
 
void send (Signal s, LinkUnits &links) const
 send signal to all links taking into account validity and local blocking More...
 
void invalidate_all (LinkUnits &links) const
 invalidate and destroy internals of all links More...
 
void remove_invalid (LinkUnits &links) const
 remove and destroy internals of invalid links More...
 
void deallocate (LinkUnit &lu) const
 deallocate function stored in a LinkUnit More...
 
LinkUnitslinkunits ()
 returns the list of LinkUnits More...
 

Private Member Functions

 SignalHub (SignalHub const &rval)
 disallow copy constructor More...
 
SignalHuboperator= (SignalHub const &rval)
 disallow copy assignment More...
 

Private Attributes

LinkUnits links_
 links specifying connections to observers More...
 
bool blocked_
 flag blocking signals from being sent More...
 
bool currently_sending_
 flag indicating SignalHub is currently in the process of sending signals; e.g. true will prevent remove_invalid() from causing any reallocation of the links_ list by erasing elements More...
 

Detailed Description

template<typename ResultType, typename Signal>
class utility::signals::SignalHub< ResultType, Signal >

forward declaration for SignalHub

primary class for function based implementation of observer pattern

This class is meant for use in implementations of the observer pattern that pass a single Signal object from the subject to its observers. An observer connects by binding one of its member functions to the SignalHub. The member function must be a unary function taking the desired Signal as its argument. Binding functions that pass references and const Signals will be interpreted correctly even if only 'Signal' is given as the template type. For example, when using a SignalHub< void, Signal > it's possible to bind the following:

However, using something like Signal & or Signal const as the template type will enforce references and/or const-ness.

Warning
SignalHub objects are not copyable.

Member Typedef Documentation

template<typename ResultType, typename Signal>
typedef boost::function1< ReturnType, Signal > utility::signals::SignalHub< ResultType, Signal >::Function
protected
template<typename ResultType, typename Signal>
typedef std::vector< Link > utility::signals::SignalHub< ResultType, Signal >::Links
protected
template<typename ResultType, typename Signal>
typedef std::vector< LinkUnitOP > utility::signals::SignalHub< ResultType, Signal >::LinkUnits
protected
template<typename ResultType, typename Signal>
typedef platform::Size utility::signals::SignalHub< ResultType, Signal >::Size

Constructor & Destructor Documentation

template<typename ResultType, typename Signal>
utility::signals::SignalHub< ResultType, Signal >::SignalHub ( )
inline

default constructor

template<typename ResultType, typename Signal>
virtual utility::signals::SignalHub< ResultType, Signal >::~SignalHub ( )
inlinevirtual

default destructor

template<typename ResultType, typename Signal>
utility::signals::SignalHub< ResultType, Signal >::SignalHub ( SignalHub< ResultType, Signal > const &  rval)
private

disallow copy constructor

Member Function Documentation

template<typename ResultType, typename Signal>
virtual void utility::signals::SignalHub< ResultType, Signal >::after_send ( )
inlineprotectedvirtual

initiate an action after send (no-op in SignalHub)

Returns
true
Remarks
override this function to get custom behavior after signal has been sent to all observers

Reimplemented in utility::signals::PausableSignalHub< ResultType, Signal >.

Referenced by utility::signals::SignalHub< ReturnType, Signal >::operator()().

template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::block ( )
inline

block signals from being sent

template<typename ResultType, typename Signal>
bool utility::signals::SignalHub< ResultType, Signal >::blocked ( ) const
inline

are signals blocked?

template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::clear ( )
inline

clear all connections

template<typename ResultType, typename Signal>
template<typename MemFn , typename Ptr >
Link utility::signals::SignalHub< ResultType, Signal >::connect ( MemFn  fn,
Ptr  ptr 
)
inline

connect an observer's member function to this hub

Template Parameters
MemFnunary member function
Parameters
fnpointer to observer's member function
ptrpointer to observer object
Returns
Link that can manage the connection

Referenced by utility::signals::SignalHub< ReturnType, Signal >::connect().

template<typename ResultType, typename Signal>
template<typename MemFn , typename Ptr >
Link utility::signals::SignalHub< ResultType, Signal >::connect ( MemFn  fn,
Ptr  ptr,
LinkUnits links 
) const
inlineprotected

connect an observer's member function to the given LinkUnits

Template Parameters
MemFnunary member function
Parameters
fnpointer to observer's member function
ptrpointer to observer object
linksfunction object gets added to this set of LinkUnits
Returns
Link that can manage the connection
template<typename ResultType, typename Signal>
Links utility::signals::SignalHub< ResultType, Signal >::current_links ( ) const
inline

return a copy of the list of links currently being managed by this SignalHub

template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::deallocate ( LinkUnit lu) const
inlineprotected
template<typename ResultType, typename Signal>
template<typename MemFn , typename Ptr >
bool utility::signals::SignalHub< ResultType, Signal >::disconnect ( MemFn  fn,
Ptr  ptr 
)
inline

disconnect an observer's member function from this hub

Template Parameters
MemFnunary member function
Parameters
fnpointer to observer's member function
ptrpointer to observer object
Returns
true if disconnect successful, false if connection does not exist

Referenced by utility::signals::SignalHub< ReturnType, Signal >::disconnect().

template<typename ResultType, typename Signal>
template<typename MemFn , typename Ptr >
bool utility::signals::SignalHub< ResultType, Signal >::disconnect ( MemFn  fn,
Ptr  ptr,
LinkUnits links 
) const
inlineprotected

disconnect an observer's member function from the given LinkUnits

Template Parameters
MemFnunary member function
Parameters
fnpointer to observer's member function
ptrpointer to observer object
linksfunction object gets removed from this set of LinkUnits
Returns
true if disconnect successful, false if connection does not exist
template<typename ResultType, typename Signal>
template<typename Functor >
LinkUnits::iterator utility::signals::SignalHub< ResultType, Signal >::find_connection ( Functor  f,
LinkUnits links 
) const
inlineprotected

find a specific connection to this hub

Template Parameters
Functorunary functor storable in Function wrapper and equality comparable with Function wrapper, typically result of boost::bind()
Returns
iterator if found, otherwise links.end()

Referenced by utility::signals::SignalHub< ReturnType, Signal >::connect(), and utility::signals::SignalHub< ReturnType, Signal >::disconnect().

template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::invalidate_all ( LinkUnits links) const
inlineprotected
template<typename ResultType, typename Signal>
LinkUnits& utility::signals::SignalHub< ResultType, Signal >::linkunits ( )
inlineprotected

returns the list of LinkUnits

template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::operator() ( Signal  s)
inline

send signal to all observers connected to the hub

template<typename ResultType, typename Signal>
SignalHub& utility::signals::SignalHub< ResultType, Signal >::operator= ( SignalHub< ResultType, Signal > const &  rval)
private

disallow copy assignment

template<typename ResultType, typename Signal>
Size utility::signals::SignalHub< ResultType, Signal >::receive_linkunits_from ( SignalHub< ResultType, Signal > const &  src)
inline

transfer linkunits from source to this SignalHub

Parameters
srcThe source SignalHub to use.
Returns
the number of links transferred
Warning
When using this function, make sure any observers not using Link connection management become aware of any changes in subject.
template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::remove_invalid ( LinkUnits links) const
inlineprotected
template<typename ResultType, typename Signal>
void utility::signals::SignalHub< ResultType, Signal >::send ( Signal  s,
LinkUnits links 
) const
inlineprotected

send signal to all links taking into account validity and local blocking

Referenced by utility::signals::SignalHub< ReturnType, Signal >::send_signal().

template<typename ResultType, typename Signal>
virtual void utility::signals::SignalHub< ResultType, Signal >::send_signal ( Signal  s)
inlineprotectedvirtual

send signal to all observers

Remarks
override this function to get custom signal sending behavior

Reimplemented in utility::signals::TokenHub< ResultType, Signal >.

Referenced by utility::signals::SignalHub< ReturnType, Signal >::operator()().

template<typename ResultType, typename Signal>
virtual bool utility::signals::SignalHub< ResultType, Signal >::signal_allowed ( Signal  const)
inlineprotectedvirtual

is signal allowed to be passed?

Returns
true if hub is not blocked, otherwise false
Remarks
override this function to get custom signal passing behavior, such as filtering or buffering

Reimplemented in utility::signals::BufferedSignalHub< ResultType, Signal >, and utility::signals::BufferedSignalHub< ReturnType, Signal >.

Referenced by utility::signals::SignalHub< ReturnType, Signal >::operator()().

template<typename ResultType, typename Signal>
Size utility::signals::SignalHub< ResultType, Signal >::size ( ) const
inline

number of connections to the hub

template<typename ResultType, typename Signal>
virtual void utility::signals::SignalHub< ResultType, Signal >::unblock ( )
inlinevirtual

allow signals to be sent

Remarks
override this to allow for custom behavior upon unblocking, such as buffer release

Reimplemented in utility::signals::BufferedSignalHub< ResultType, Signal >, and utility::signals::BufferedSignalHub< ReturnType, Signal >.

Member Data Documentation

template<typename ResultType, typename Signal>
bool utility::signals::SignalHub< ResultType, Signal >::blocked_
private
template<typename ResultType, typename Signal>
bool utility::signals::SignalHub< ResultType, Signal >::currently_sending_
mutableprivate

flag indicating SignalHub is currently in the process of sending signals; e.g. true will prevent remove_invalid() from causing any reallocation of the links_ list by erasing elements

Referenced by utility::signals::SignalHub< ReturnType, Signal >::remove_invalid(), and utility::signals::SignalHub< ReturnType, Signal >::send().

template<typename ResultType, typename Signal>
LinkUnits utility::signals::SignalHub< ResultType, Signal >::links_
mutableprivate

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