Medical Imaging Interaction Toolkit  2023.12.99-7a59bd54
Medical Imaging Interaction Toolkit
mitkGetClassHierarchy.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 mitkGetClassHierarchy_h
14 #define mitkGetClassHierarchy_h
15 
16 #include <string>
17 #include <vector>
18 
19 namespace mitk
20 {
21 #ifndef DOXYGEN_SKIP
22 
23  template <typename T>
25  {
26  typedef char Small;
27  struct Big
28  {
29  char dummy[2];
30  };
31 
32  template <const char *(*)()>
33  struct SFINAE
34  {
35  };
36  template <typename U>
37  static Small Test(SFINAE<&U::GetStaticNameOfClass> *);
38  template <typename U>
39  static Big Test(...);
40 
41  public:
42  enum
43  {
44  value = sizeof(Test<T>(nullptr)) == sizeof(Small)
45  };
46  };
47 
48  template <typename T, bool>
50  {
51  static std::string value() { return typeid(T).name(); }
52  };
53 
54  template <typename T>
55  struct StaticNameOfClass<T, true>
56  {
57  static std::string value() { return T::GetStaticNameOfClass(); }
58  };
59 
60  template <typename T>
62  {
63  typedef char Small;
64  struct Big
65  {
66  char dummy[2];
67  };
68 
69  template <typename U>
70  static Small Test(typename U::Superclass *);
71  template <typename U>
72  static Big Test(...);
73 
74  public:
75  enum
76  {
77  value = sizeof(Test<T>(nullptr)) == sizeof(Small)
78  };
79  };
80 
81  template <typename T, bool>
83  {
84  typedef void value;
85  };
86 
87  template <typename T>
88  struct GetSuperclassType<T, true>
89  {
90  typedef typename T::Superclass value;
91  };
92 
93  template <typename T>
94  std::vector<std::string> GetClassHierarchy();
95 
96  template <>
97  inline std::vector<std::string> GetClassHierarchy<void>()
98  {
99  return std::vector<std::string>();
100  }
101 
102 #endif
103 
111  template <typename T>
112  std::vector<std::string> GetClassHierarchy()
113  {
114  std::vector<std::string> result;
116  if (!name.empty())
117  result.push_back(name);
118  std::vector<std::string> superHierarchy =
119  GetClassHierarchy<typename GetSuperclassType<T, HasTypeSuperclass<T>::value>::value>();
120  result.insert(result.end(), superHierarchy.begin(), superHierarchy.end());
121  return result;
122  }
123 }
124 
125 #endif
mitk::HasMethodGetStaticNameOfClass::value
@ value
Definition: mitkGetClassHierarchy.h:44
mitk::GetSuperclassType< T, true >::value
T::Superclass value
Definition: mitkGetClassHierarchy.h:90
mitk::HasTypeSuperclass
Definition: mitkGetClassHierarchy.h:61
mitk::HasTypeSuperclass::value
@ value
Definition: mitkGetClassHierarchy.h:77
mitk::GetSuperclassType::value
void value
Definition: mitkGetClassHierarchy.h:84
mitk::StaticNameOfClass
Definition: mitkGetClassHierarchy.h:49
mitk::HasMethodGetStaticNameOfClass
Definition: mitkGetClassHierarchy.h:24
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::StaticNameOfClass< T, true >::value
static std::string value()
Definition: mitkGetClassHierarchy.h:57
mitk::StaticNameOfClass::value
static std::string value()
Definition: mitkGetClassHierarchy.h:51
mitk::GetClassHierarchy< void >
std::vector< std::string > GetClassHierarchy< void >()
Definition: mitkGetClassHierarchy.h:97
mitk::GetClassHierarchy
std::vector< std::string > GetClassHierarchy()
Definition: mitkGetClassHierarchy.h:112
mitk::GetSuperclassType
Definition: mitkGetClassHierarchy.h:82