Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
mrpt::utils::CObservable Class Reference

Detailed Description

Inherit from this class for those objects capable of being observed by a CObserver class.

The only thing to do in your child class is to call CObservable::publishEvent() whenever needed and all the observer classes will be notified.

Note:
The pairs CObservable / CObserver automatically notify each other the destruction of any of them, effectively ending the subscription of events.
See also:
CObserver, mrptEvent

#include <mrpt/utils/CObservable.h>

Inheritance diagram for mrpt::utils::CObservable:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CObservable ()
virtual ~CObservable ()

Protected Member Functions

void publishEvent (const mrptEvent &e) const
 Called when you want this object to emit an event to all the observers currently subscribed to this object.
bool hasSubscribers () const
 Can be called by a derived class before preparing an event for publishing with publishEvent to determine if there is no one subscribed, so it can save the wasted time preparing an event that will be not read.

Private Member Functions

void internal_observer_begin (CObserver *)
void internal_observer_end (CObserver *)

Private Attributes

std::set< CObserver * > m_subscribers

Friends

class CObserver

Constructor & Destructor Documentation

mrpt::utils::CObservable::CObservable ( )
virtual mrpt::utils::CObservable::~CObservable ( ) [virtual]

Member Function Documentation

bool mrpt::utils::CObservable::hasSubscribers ( ) const [inline, protected]

Can be called by a derived class before preparing an event for publishing with publishEvent to determine if there is no one subscribed, so it can save the wasted time preparing an event that will be not read.

Definition at line 69 of file CObservable.h.

void mrpt::utils::CObservable::internal_observer_begin ( CObserver ) [private]
void mrpt::utils::CObservable::internal_observer_end ( CObserver ) [private]
void mrpt::utils::CObservable::publishEvent ( const mrptEvent e) const [protected]

Called when you want this object to emit an event to all the observers currently subscribed to this object.


Friends And Related Function Documentation

friend class CObserver [friend]

Definition at line 52 of file CObservable.h.


Member Data Documentation

Definition at line 59 of file CObservable.h.




Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011