Medical Imaging Interaction Toolkit  2018.4.99-1640525a
Medical Imaging Interaction Toolkit
mitk::Message< A > Class Template Reference

Event/message/notification class. More...

#include <mitkMessage.h>

Inheritance diagram for mitk::Message< A >:
Collaboration diagram for mitk::Message< A >:

Public Types

typedef MessageBase< MessageAbstractDelegate< A > > Super
typedef Super::ListenerList ListenerList
- Public Types inherited from mitk::MessageBase< MessageAbstractDelegate< A > >
typedef std::vector< MessageAbstractDelegate< A > *> ListenerList

Public Member Functions

void Send ()
void operator() ()
- Public Member Functions inherited from mitk::MessageBase< MessageAbstractDelegate< A > >
virtual ~MessageBase ()
 MessageBase ()
 MessageBase (const MessageBase &o)
MessageBaseoperator= (const MessageBase &o)
void AddListener (const MessageAbstractDelegate< A > &delegate) const
void operator+= (const MessageAbstractDelegate< A > &delegate) const
void RemoveListener (const MessageAbstractDelegate< A > &delegate) const
void operator-= (const MessageAbstractDelegate< A > &delegate) const
const ListenerListGetListeners () const
bool HasListeners () const
bool IsEmpty () const

Additional Inherited Members

- Protected Attributes inherited from mitk::MessageBase< MessageAbstractDelegate< A > >
ListenerList m_Listeners
 List of listeners. More...
itk::SimpleFastMutexLock m_Mutex

Detailed Description

template<typename A = void>
class mitk::Message< A >

Event/message/notification class.

See also

This totally ITK, Qt, VTK, whatever toolkit independent class allows one class to send out messages and another class to receive these message. This class is templated over the return type (A) of the callback functions. There are variations of this class (Message1, Message2, etc.) for sending one, two or more parameters along with the messages.

This is an implementation of the Observer pattern.

  • There is no guarantee about the order of which observer is notified first. At the moment the observers which register first will be notified first.
  • Notifications are synchronous, by direct method calls. There is no support for asynchronous messages.

To conveniently add methods for registering/unregistering observers to Message variables of your class, you can use the mitkNewMessageMacro macros.

Here is an example how to use the macros and templates:

// An object to be send around
class Law
std::string m_Description;
Law(const std::string law) : m_Description(law)
{ }
std::string GetDescription() const
return m_Description;
// The NewtonMachine will issue specific events
class NewtonMachine
mitkNewMessage1Macro(AnalysisStopped, bool);
mitkNewMessage1Macro(LawDiscovered, const Law&);
void StartAnalysis()
// send the "started" signal
// we found a new law of nature by creating one :-)
Law massLaw("F=ma");
void StopAnalysis()
// send the "stop" message with false, indicating
// that no error occured
class Observer
NewtonMachine* m_Machine;
Observer(NewtonMachine* machine) : m_Machine(machine)
// Add "observers", i.e. function pointers to the machine
::mitk::MessageDelegate<Observer>(this, &Observer::MachineStarted));
::mitk::MessageDelegate1<Observer, bool>(this, &Observer::MachineStopped));
::mitk::MessageDelegate1<Observer, const Law&>(this, &Observer::LawDiscovered));
// Always remove your observers when finished
::mitk::MessagDelegate<Observer>(this, &Observer::MachineStarted));
::mitk::MessageDelegate1<Observer, bool>(this, &Observer::MachineStopped));
::mitk::MessageDelegate1<Observer, const Law&>(this, &Observer::LawDiscovered));
void MachineStarted()
std::cout << "Observed machine has started" << std::endl;
void MachineStopped(bool error)
std::cout << "Observed machine stopped " << (error ? "with an error" : "") << std::endl;
void LawDiscovered(const Law& law)
std::cout << "New law of nature discovered: " << law.GetDescription() << std::endl;
NewtonMachine newtonMachine;
Observer observer(&newtonMachine);
// This will send two events to registered observers
// This will send one event to registered observers

Another example of how to use these message classes can be found in the directory Testing, file mitkMessageTest.cpp

Definition at line 568 of file mitkMessage.h.

Member Typedef Documentation

◆ ListenerList

template<typename A = void>
typedef Super::ListenerList mitk::Message< A >::ListenerList

Definition at line 572 of file mitkMessage.h.

◆ Super

template<typename A = void>
typedef MessageBase<MessageAbstractDelegate<A> > mitk::Message< A >::Super

Definition at line 571 of file mitkMessage.h.

Member Function Documentation

◆ operator()()

template<typename A = void>
void mitk::Message< A >::operator() ( )

Definition at line 591 of file mitkMessage.h.

◆ Send()

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