MRPT  2.0.1
List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
mrpt::system::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

Definition at line 31 of file CObservable.h.

#include <mrpt/system/CObservable.h>

Inheritance diagram for mrpt::system::CObservable:

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. More...
 
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. More...
 

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

◆ CObservable()

CObservable::CObservable ( )
default

◆ ~CObservable()

CObservable::~CObservable ( )
virtual

Definition at line 21 of file CObservable.cpp.

References mrpt::exception_to_str().

Here is the call graph for this function:

Member Function Documentation

◆ hasSubscribers()

bool mrpt::system::CObservable::hasSubscribers ( ) const
inlineprotected

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 53 of file CObservable.h.

References m_subscribers.

Referenced by mrpt::gui::CWindowDialog::OnMouseDown(), mrpt::gui::CWindowDialog::OnMouseMove(), mrpt::gui::CWindowDialog::OnResize(), mrpt::opengl::COpenGLViewport::render(), and mrpt::opengl::COpenGLViewport::renderNormalSceneMode().

Here is the caller graph for this function:

◆ internal_observer_begin()

void CObservable::internal_observer_begin ( CObserver o)
private

Definition at line 38 of file CObservable.cpp.

Referenced by mrpt::system::CObserver::observeBegin().

Here is the caller graph for this function:

◆ internal_observer_end()

void CObservable::internal_observer_end ( CObserver o)
private

Definition at line 43 of file CObservable.cpp.

References ASSERTMSG_, MRPT_END, and MRPT_START.

◆ publishEvent()

void 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.

Definition at line 57 of file CObservable.cpp.

References MRPT_END, and MRPT_START.

Referenced by mrpt::gui::CDisplayWindow3D::internal_emitGrabImageEvent(), mrpt::gui::CWindowDialog::OnChar(), mrpt::gui::CWindowDialog::OnClose(), mrpt::gui::C3DWindowDialog::OnClose(), mrpt::gui::CWindowDialog::OnMouseDown(), mrpt::gui::CWindowDialog::OnMouseMove(), mrpt::gui::CWindowDialog::OnResize(), mrpt::gui::C3DWindowDialog::OnResize(), mrpt::opengl::COpenGLViewport::render(), and mrpt::opengl::COpenGLViewport::renderNormalSceneMode().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CObserver

friend class CObserver
friend

Definition at line 33 of file CObservable.h.

Member Data Documentation

◆ m_subscribers

std::set<CObserver*> mrpt::system::CObservable::m_subscribers
private

Definition at line 40 of file CObservable.h.

Referenced by hasSubscribers().




Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020