Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 // MITKGETCLASSHIERARCHY_H
DataCollection - Class to facilitate loading/accessing structured data.
static std::string value()
std::vector< std::string > GetClassHierarchy< void >()
std::vector< std::string > GetClassHierarchy()