Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKGETCLASSHIERARCHY_H
18 #define MITKGETCLASSHIERARCHY_H
19 
20 #include <string>
21 #include <vector>
22 
23 namespace mitk
24 {
25 #ifndef DOXYGEN_SKIP
26 
27  template <typename T>
29  {
30  typedef char Small;
31  struct Big
32  {
33  char dummy[2];
34  };
35 
36  template <const char *(*)()>
37  struct SFINAE
38  {
39  };
40  template <typename U>
41  static Small Test(SFINAE<&U::GetStaticNameOfClass> *);
42  template <typename U>
43  static Big Test(...);
44 
45  public:
46  enum
47  {
48  value = sizeof(Test<T>(nullptr)) == sizeof(Small)
49  };
50  };
51 
52  template <typename T, bool>
54  {
55  static std::string value() { return typeid(T).name(); }
56  };
57 
58  template <typename T>
59  struct StaticNameOfClass<T, true>
60  {
61  static std::string value() { return T::GetStaticNameOfClass(); }
62  };
63 
64  template <typename T>
66  {
67  typedef char Small;
68  struct Big
69  {
70  char dummy[2];
71  };
72 
73  template <typename U>
74  static Small Test(typename U::Superclass *);
75  template <typename U>
76  static Big Test(...);
77 
78  public:
79  enum
80  {
81  value = sizeof(Test<T>(nullptr)) == sizeof(Small)
82  };
83  };
84 
85  template <typename T, bool>
87  {
88  typedef void value;
89  };
90 
91  template <typename T>
92  struct GetSuperclassType<T, true>
93  {
94  typedef typename T::Superclass value;
95  };
96 
97  template <typename T>
98  std::vector<std::string> GetClassHierarchy();
99 
100  template <>
101  inline std::vector<std::string> GetClassHierarchy<void>()
102  {
103  return std::vector<std::string>();
104  }
105 
106 #endif
107 
115  template <typename T>
116  std::vector<std::string> GetClassHierarchy()
117  {
118  std::vector<std::string> result;
120  if (!name.empty())
121  result.push_back(name);
122  std::vector<std::string> superHierarchy =
123  GetClassHierarchy<typename GetSuperclassType<T, HasTypeSuperclass<T>::value>::value>();
124  result.insert(result.end(), superHierarchy.begin(), superHierarchy.end());
125  return result;
126  }
127 }
128 
129 #endif // MITKGETCLASSHIERARCHY_H
DataCollection - Class to facilitate loading/accessing structured data.
static std::string value()
itkEventMacroDeclaration(FocusChangedEvent, itk::AnyEvent) class MITKCORE_EXPORT TestingRenderingManager typedef RenderingManager Superclass
std::vector< std::string > GetClassHierarchy< void >()
static const char * GetStaticNameOfClass()
std::vector< std::string > GetClassHierarchy()