Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkITKEventObserverGuard.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkITKEventObserverGuard_h
14 #define mitkITKEventObserverGuard_h
15 
16 #include <functional>
17 #include <memory>
18 #include <MitkCoreExports.h>
19 
20 namespace itk
21 {
22  class Object;
23  class Command;
24  class EventObject;
25 }
26 
27 namespace mitk
28 {
58  {
59  public:
62 
69  ITKEventObserverGuard(const itk::Object* sender, unsigned long observerTag);
70 
78  ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, itk::Command* command);
79 
87  ITKEventObserverGuard(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function);
88 
91 
94 
97 
105  void Reset();
106 
116  void Reset(const itk::Object* sender, unsigned long observerTag);
117 
128  void Reset(const itk::Object* sender, const itk::EventObject& event, itk::Command* command);
129 
140  void Reset(const itk::Object* sender, const itk::EventObject& event, std::function<void(const itk::EventObject&)> function);
141 
147  bool IsInitialized() const;
148 
149  private:
150  struct Impl;
151  std::unique_ptr<Impl> m_ITKEventObserverGuardImpl;
152  };
153 
154 
155 }
156 
157 #endif
#define MITKCORE_EXPORT
Convenience class that helps to manage the lifetime of itk event observers.
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.
ITKEventObserverGuard(ITKEventObserverGuard &&)
Move constructor. Transfers ownership of the guarded observer.
void Reset(const itk::Object *sender, unsigned long observerTag)
Reset the guard and start guarding a new observer tag.
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.
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.
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.
void Reset()
Reset the guard by removing the currently guarded observer.
bool IsInitialized() const
Check whether this guard is currently managing an observer.
ITKEventObserverGuard(const itk::Object *sender, unsigned long observerTag)
Construct a guard for an existing observer tag.
ITKEventObserverGuard()
Construct an uninitialized guard (no observer is guarded).
~ITKEventObserverGuard()
Destructor. Removes the guarded observer from the sender if still alive.
ITKEventObserverGuard & operator=(ITKEventObserverGuard &&)
Move assignment. Releases any currently guarded observer and takes ownership from the other guard.
Find image slices visible on a given plane.