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

BufferedSignalHub capable of passing observers. More...

#include <TokenHub.hh>

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

List of all members.

Public Types

typedef Super::Size Size

Public Member Functions

 TokenHub ()
 default constructor
virtual ~TokenHub ()
 default destructor
Size receive_tokens_from (TokenHub const &src)
 receive tokenized connections from source and remove them from source
Size n_tokens () const
 number of tokenized connections
void clear_tokens ()
 clear only tokenized connections, will invalidate all tokens
template<typename MemFn , typename Ptr >
Link connect_tokenize (MemFn fn, Ptr ptr)
 connect and tokenize an observer's member function
template<typename MemFn , typename Ptr >
bool disconnect (MemFn fn, Ptr ptr)
 disconnect an observer's member function
template<typename MemFn , typename Ptr >
bool disconnect_tokenize (MemFn fn, Ptr ptr)
 disconnect an observer's tokenized member function

Protected Member Functions

virtual void send_signal (Signal s)
 send signal to both regular and tokenized connections

Detailed Description

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

BufferedSignalHub capable of passing observers.

If an observer's member function is connected with the 'tokenize' flag, then this function is allowed to permanently pass from a source TokenHub to a destination TokenHub via a call to receive_tokens_from(), which will erase the observer function from the source hub. The observer member function, in effect, becomes a single token which is intended to be passed from Subject to Subject upon copy (see remarks in receive_tokens_from() for different behavior in copy construct vs copy assign). Invalidating the Link will stop the token from being passed from Subject to Subject. Use the token ability with care, as it depends on the programmer to consistently do the right thing and make sure Observer and Subject(s) do not loose sync with each other. Observers that communicate via a tokenized member function are recommended to follow the following guidelines:

Warning:
Only use this class when necessary, as usage of the token ability can introduce too much ambiguity into deciding whether an Observer or Subject still exists. Most users should think about using a BufferedSignalHub instead and managing the connections manually.

Member Typedef Documentation

template<typename ReturnType , typename Signal >
typedef Super::Size utility::signals::TokenHub< ReturnType, Signal >::Size

Constructor & Destructor Documentation

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

default constructor

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

Member Function Documentation

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

clear only tokenized connections, will invalidate all tokens

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

template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
Link utility::signals::TokenHub< ReturnType, Signal >::connect_tokenize ( MemFn  fn,
Ptr  ptr 
) [inline]

connect and tokenize an observer's member function

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

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

template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
bool utility::signals::TokenHub< ReturnType, Signal >::disconnect ( MemFn  fn,
Ptr  ptr 
) [inline]

disconnect an observer's member function

will search both regular and tokenized functions

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 from utility::signals::SignalHub< ReturnType, Signal >.

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

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

template<typename ReturnType , typename Signal >
template<typename MemFn , typename Ptr >
bool utility::signals::TokenHub< ReturnType, Signal >::disconnect_tokenize ( MemFn  fn,
Ptr  ptr 
) [inline]

disconnect an observer's tokenized member function

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

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

template<typename ReturnType , typename Signal >
Size utility::signals::TokenHub< ReturnType, Signal >::n_tokens ( ) const [inline]

number of tokenized connections

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

template<typename ReturnType , typename Signal >
Size utility::signals::TokenHub< ReturnType, Signal >::receive_tokens_from ( TokenHub< ReturnType, Signal > const &  src) [inline]

receive tokenized connections from source and remove them from source

Remarks:
Use this within either copy constructor or copy assignment of Subject. Use within a copy constructor will give behavior that tends to keep the token from descending too far down in the call graph, while use within copy assignment will give behavior that can drill deep down into the call graph and has the potential of getting trapped at the lowest level.
Returns:
the number of tokens transferred

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

template<typename ReturnType , typename Signal >
virtual void utility::signals::TokenHub< ReturnType, Signal >::send_signal ( Signal  s) [inline, protected, virtual]

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