|
Medical Imaging Interaction Toolkit
2026.06.00
Medical Imaging Interaction Toolkit
|
Convenience class that helps to manage the lifetime of itk event observers. More...
#include <mitkITKEventObserverGuard.h>
Public Member Functions | |
| ITKEventObserverGuard () | |
| Construct an uninitialized guard (no observer is guarded). More... | |
| ITKEventObserverGuard (const itk::Object *sender, unsigned long observerTag) | |
| Construct a guard for an existing observer tag. More... | |
| ITKEventObserverGuard (const itk::Object *sender, const itk::EventObject &event, itk::Command *command) | |
| Construct a guard that adds and manages an observer using an itk::Command. More... | |
| ITKEventObserverGuard (const itk::Object *sender, const itk::EventObject &event, std::function< void(const itk::EventObject &)> function) | |
| Construct a guard that adds and manages an observer using a lambda or function. More... | |
| ITKEventObserverGuard (ITKEventObserverGuard &&) | |
| Move constructor. Transfers ownership of the guarded observer. More... | |
| ITKEventObserverGuard & | operator= (ITKEventObserverGuard &&) |
| Move assignment. Releases any currently guarded observer and takes ownership from the other guard. More... | |
| ~ITKEventObserverGuard () | |
| Destructor. Removes the guarded observer from the sender if still alive. More... | |
| void | Reset () |
| Reset the guard by removing the currently guarded observer. More... | |
| void | Reset (const itk::Object *sender, unsigned long observerTag) |
| Reset the guard and start guarding a new observer tag. More... | |
| void | Reset (const itk::Object *sender, const itk::EventObject &event, itk::Command *command) |
| Reset the guard and add a new observer using an itk::Command. More... | |
| void | Reset (const itk::Object *sender, const itk::EventObject &event, std::function< void(const itk::EventObject &)> function) |
| Reset the guard and add a new observer using a lambda or function. More... | |
| bool | IsInitialized () const |
| Check whether this guard is currently managing an observer. More... | |
Convenience class that helps to manage the lifetime of itk event observers.
This helper class can be used to ensure itk event observers are removed from a sender object at the end of a certain scope. This class behaves similar to a std::unique_ptr but for event observers. Therefore the observer will be removed from the sender when one of the following conditions are met:
Sample usage:
This will add an observer to o executing the lambda for any event as long as the guard exists.
Definition at line 57 of file mitkITKEventObserverGuard.h.
| mitk::ITKEventObserverGuard::ITKEventObserverGuard | ( | ) |
Construct an uninitialized guard (no observer is guarded).
| mitk::ITKEventObserverGuard::ITKEventObserverGuard | ( | const itk::Object * | sender, |
| unsigned long | observerTag | ||
| ) |
Construct a guard for an existing observer tag.
| sender | The ITK object that owns the observer. |
| observerTag | The tag returned by itk::Object::AddObserver(). |
| mitk::ITKEventObserverGuard::ITKEventObserverGuard | ( | const itk::Object * | sender, |
| const itk::EventObject & | event, | ||
| itk::Command * | command | ||
| ) |
Construct a guard that adds and manages an observer using an itk::Command.
| sender | The ITK object to observe. |
| event | The event type to observe. |
| command | The command to execute when the event occurs. |
| mitk::ITKEventObserverGuard::ITKEventObserverGuard | ( | const itk::Object * | sender, |
| const itk::EventObject & | event, | ||
| std::function< void(const itk::EventObject &)> | function | ||
| ) |
Construct a guard that adds and manages an observer using a lambda or function.
| sender | The ITK object to observe. |
| event | The event type to observe. |
| function | The function to execute when the event occurs. |
| mitk::ITKEventObserverGuard::ITKEventObserverGuard | ( | ITKEventObserverGuard && | ) |
Move constructor. Transfers ownership of the guarded observer.
| mitk::ITKEventObserverGuard::~ITKEventObserverGuard | ( | ) |
Destructor. Removes the guarded observer from the sender if still alive.
| bool mitk::ITKEventObserverGuard::IsInitialized | ( | ) | const |
Check whether this guard is currently managing an observer.
true if the guard is initialized and managing an observer, false otherwise. | ITKEventObserverGuard& mitk::ITKEventObserverGuard::operator= | ( | ITKEventObserverGuard && | ) |
Move assignment. Releases any currently guarded observer and takes ownership from the other guard.
| void mitk::ITKEventObserverGuard::Reset | ( | ) |
Reset the guard by removing the currently guarded observer.
After the reset, the guard is uninitialized.
| void mitk::ITKEventObserverGuard::Reset | ( | const itk::Object * | sender, |
| const itk::EventObject & | event, | ||
| itk::Command * | command | ||
| ) |
Reset the guard and add a new observer using an itk::Command.
First removes the currently guarded observer, then adds a new observer for the passed sender with the passed event and command. The new observer is now guarded.
| sender | The ITK object to observe. |
| event | The event type to observe. |
| command | The command to execute when the event occurs. |
| void mitk::ITKEventObserverGuard::Reset | ( | const itk::Object * | sender, |
| const itk::EventObject & | event, | ||
| std::function< void(const itk::EventObject &)> | function | ||
| ) |
Reset the guard and add a new observer using a lambda or function.
First removes the currently guarded observer, then adds a new observer for the passed sender with the passed event and function. The new observer is now guarded.
| sender | The ITK object to observe. |
| event | The event type to observe. |
| function | The function to execute when the event occurs. |
| void mitk::ITKEventObserverGuard::Reset | ( | const itk::Object * | sender, |
| unsigned long | observerTag | ||
| ) |
Reset the guard and start guarding a new observer tag.
First removes the currently guarded observer, then guards the passed observer tag for the passed sender.
| sender | The ITK object that owns the observer. |
| observerTag | The tag returned by itk::Object::AddObserver(). |