Rosetta 3.3
Public Types | Public Member Functions | Protected Types | Protected Member Functions
utility::signals::SignalHub< ReturnType, Signal > Class Template Reference

primary class for function based implementation of observer pattern More...

#include <SignalHub.hh>

Inheritance diagram for utility::signals::SignalHub< ReturnType, Signal >:
Inheritance graph
[legend]
Collaboration diagram for utility::signals::SignalHub< ReturnType, Signal >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef platform::Size Size

Public Member Functions

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

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

Detailed Description

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

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 ReturnType , typename Signal >
typedef boost::function1< ReturnType, Signal > utility::signals::SignalHub< ReturnType, Signal >::Function [protected]
template<typename ReturnType , typename Signal >
typedef std::vector< Link > utility::signals::SignalHub< ReturnType, Signal >::Links [protected]
template<typename ReturnType , typename Signal >
typedef std::vector< LinkUnitOP > utility::signals::SignalHub< ReturnType, Signal >::LinkUnits [protected]
template<typename ReturnType , typename Signal >
typedef platform::Size utility::signals::SignalHub< ReturnType, Signal >::Size

Constructor & Destructor Documentation

template<typename ReturnType , typename Signal >
utility::signals::SignalHub< ReturnType, Signal >::SignalHub ( ) [inline]

default constructor

template<typename ReturnType , typename Signal >
virtual utility::signals::SignalHub< ReturnType, Signal >::~SignalHub ( ) [inline, virtual]

Member Function Documentation

template<typename ReturnType , typename Signal >
virtual void utility::signals::SignalHub< ReturnType, Signal >::after_send ( ) [inline, protected, virtual]

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< ReturnType, Signal >.

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

template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::block ( ) [inline]

block signals from being sent

Referenced by utility::signals::BufferedSignalHub< ReturnType, Signal >::buffer().

template<typename ReturnType , typename Signal >
bool utility::signals::SignalHub< ReturnType, Signal >::blocked ( ) const [inline]
template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::clear ( ) [inline]
template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
Link utility::signals::SignalHub< ReturnType, 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::TokenHub< ReturnType, Signal >::connect_tokenize().

template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
Link utility::signals::SignalHub< ReturnType, Signal >::connect ( MemFn  fn,
Ptr  ptr,
LinkUnits links 
) const [inline, protected]

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

References utility::signals::SignalHub< ReturnType, Signal >::find_connection(), color_pdb::i, and utility::signals::SignalHub< ReturnType, Signal >::remove_invalid().

template<typename ReturnType , typename Signal >
Links utility::signals::SignalHub< ReturnType, Signal >::current_links ( ) const [inline]

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

References basic::options::OptionKeys::in::file::l.

template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::deallocate ( LinkUnit lu) const [inline, protected]
template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
bool utility::signals::SignalHub< ReturnType, 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

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

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

template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
bool utility::signals::SignalHub< ReturnType, Signal >::disconnect ( MemFn  fn,
Ptr  ptr,
LinkUnits links 
) const [inline, protected]

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

References utility::signals::SignalHub< ReturnType, Signal >::deallocate(), utility::signals::SignalHub< ReturnType, Signal >::find_connection(), color_pdb::i, and utility::signals::SignalHub< ReturnType, Signal >::remove_invalid().

template<typename ReturnType , typename Signal >
template<typename Functor >
LinkUnits::iterator utility::signals::SignalHub< ReturnType, Signal >::find_connection ( Functor  f,
LinkUnits links 
) const [inline, protected]

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()

References make_table_of_pilot_apps::f, and color_pdb::i.

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

template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::invalidate_all ( LinkUnits links) const [inline, protected]
template<typename ReturnType , typename Signal >
LinkUnits& utility::signals::SignalHub< ReturnType, Signal >::linkunits ( ) [inline, protected]

returns the list of LinkUnits

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

template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::operator() ( Signal  s) [inline]
template<typename ReturnType , typename Signal >
Size utility::signals::SignalHub< ReturnType, Signal >::receive_linkunits_from ( SignalHub< ReturnType, 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.

References utility::signals::SignalHub< ReturnType, Signal >::remove_invalid(), and utility::signals::SignalHub< ReturnType, Signal >::size().

template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::remove_invalid ( LinkUnits links) const [inline, protected]
template<typename ReturnType , typename Signal >
void utility::signals::SignalHub< ReturnType, Signal >::send ( Signal  s,
LinkUnits links 
) const [inline, protected]
template<typename ReturnType , typename Signal >
virtual void utility::signals::SignalHub< ReturnType, Signal >::send_signal ( Signal  s) [inline, protected, virtual]

send signal to all observers

Remarks:
override this function to get custom signal sending behavior

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

References utility::signals::SignalHub< ReturnType, Signal >::send().

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

template<typename ReturnType , typename Signal >
virtual bool utility::signals::SignalHub< ReturnType, Signal >::signal_allowed ( Signal  const) [inline, protected, virtual]

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< ReturnType, Signal >.

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

template<typename ReturnType , typename Signal >
Size utility::signals::SignalHub< ReturnType, Signal >::size ( ) const [inline]
template<typename ReturnType , typename Signal >
virtual void utility::signals::SignalHub< ReturnType, Signal >::unblock ( ) [inline, virtual]

allow signals to be sent

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

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

Referenced by utility::signals::BufferedSignalHub< ReturnType, Signal >::unblock().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines