Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkIPropertyTransience.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 mitkIPropertyTransience_h
14 #define mitkIPropertyTransience_h
15 
16 #include <mitkBaseData.h>
17 #include <mitkServiceInterface.h>
18 
19 #include <MitkCoreExports.h>
20 
21 #include <functional>
22 #include <string>
23 #include <type_traits>
24 
25 namespace mitk
26 {
43  {
44  public:
46 
54  template <class TData, typename = std::enable_if_t<std::is_base_of_v<BaseData, TData>>>
55  void AddTransient(const std::string &propertyName)
56  {
57  if constexpr (std::is_same_v<TData, BaseData>)
58  {
59  // A rule for BaseData applies to every node, including data-less ones
60  // where data is null and a dynamic_cast would fail. Match unconditionally.
61  this->InternalAddTransient(propertyName, [](const BaseData *) { return true; });
62  }
63  else
64  {
65  this->InternalAddTransient(propertyName,
66  [](const BaseData *data) { return dynamic_cast<const TData *>(data) != nullptr; });
67  }
68  }
69 
78  virtual bool IsTransient(const BaseData *data, const std::string &propertyName) const = 0;
79 
80  protected:
89  virtual void InternalAddTransient(const std::string &propertyName,
90  std::function<bool(const BaseData *)> dataTypeMatcher) = 0;
91  };
92 }
93 
94 MITK_DECLARE_SERVICE_INTERFACE(mitk::IPropertyTransience, "org.mitk.IPropertyTransience")
95 
96 #endif
#define MITKCORE_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Interface of the property transience service.
void AddTransient(const std::string &propertyName)
Declare a property transient for nodes whose data is-a TData.
virtual bool IsTransient(const BaseData *data, const std::string &propertyName) const =0
Check whether a property is transient for the given node data.
virtual void InternalAddTransient(const std::string &propertyName, std::function< bool(const BaseData *)> dataTypeMatcher)=0
Register a transient property with a data-type matcher.
Provides the MITK_DECLARE_SERVICE_INTERFACE macro for registering C++ interfaces with both the CppMic...
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
Declare a C++ interface for use with CppMicroServices (Qt not available).
Find image slices visible on a given plane.