mpqc::utility::Observable< Derived > Class Template Reference
Collaboration diagram for mpqc::utility::Observable< Derived >:

Documentation

template<typename Derived>
class mpqc::utility::Observable< Derived >

helps to set up messaging between objects via the Observer pattern

Use as a base class for any class that wants to send messages to other recipients. Recipients register callbacks by calling Observable::register_message .

Note
Observable holds weak (non-owning) pointers to the observers. Message lifetime is managed automatically as long as the observers derive from the Observer class. Observer will hold std::shared_ptr to this, hence the need for the mpqc::enable_shared_from_this base.
See also
Observer
Template Parameters
Derivedthe derived class for which std::shared_ptr exists (as required for mpqc::enable_shared_from_this to be usable)

Public Types

typedef std::map< void *, std::function< void()> > messages_type
 

Public Member Functions

template<typename Observer >
std::shared_ptr< void *const > register_message (Observer *observer, std::function< void()> message) const
 
- Public Member Functions inherited from mpqc::enable_shared_from_this< Derived >
virtual ~enable_shared_from_this ()=default
 
std::shared_ptr< Derived > shared_from_this ()
 returns the pointer to this object More...
 
std::shared_ptr< std::add_const_t< Derived > > shared_from_this () const
 returns the pointer to this object More...
 
- Public Member Functions inherited from mpqc::detail::virt_base_of_enable_shared_from_this
virtual ~virt_base_of_enable_shared_from_this ()=default
 
bool shared_from_this_possible () const
 
template<typename Target , typename = std::enable_if_t<!std::is_const_v<Target>>>
std::shared_ptr< Target > cast_shared_from_this_to ()
 returns the pointer to this cast to a particular type More...
 
template<typename Target >
std::shared_ptr< std::add_const_t< Target > > cast_shared_from_this_to () const
 returns the pointer to this cast to a particular type More...
 

Protected Member Functions

void message ()
 

Member Typedef Documentation

◆ messages_type

template<typename Derived >
typedef std::map<void *, std::function<void()> > mpqc::utility::Observable< Derived >::messages_type

Member Function Documentation

◆ message()

template<typename Derived >
void mpqc::utility::Observable< Derived >::message ( )
inlineprotected

◆ register_message()

template<typename Derived >
template<typename Observer >
std::shared_ptr<void *const> mpqc::utility::Observable< Derived >::register_message ( Observer observer,
std::function< void()>  message 
) const
inline

adds a message to the list, returns a receipt that the observer needs to destroy at the end of its life (i.e., in the dtor).


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