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
berryReflection.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
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 #include "berryReflection.h"
18 
19 #include "berryObject.h"
20 
21 #include <QStringList>
22 
23 // Better name demangling for gcc
24 #if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 )
25 #define GCC_USEDEMANGLE
26 #endif
27 
28 #ifdef GCC_USEDEMANGLE
29 #include <cstdlib>
30 #include <cxxabi.h>
31 #endif
32 
33 #if defined(_WIN32) && defined(NDEBUG)
34 // exported from VC CRT
35 extern "C"
36 char * __unDName(char * outputString, const char * name, int maxStringLength,
37  void * (* pAlloc )(size_t), void (* pFree )(void *),
38  unsigned short disableFlags);
39 #endif
40 
41 namespace berry {
42 
43 namespace Reflection {
44 
45 QString DemangleName(const char* mangledName)
46 {
47  QString name(mangledName);
48 #ifdef GCC_USEDEMANGLE
49  int status;
50  char* unmangled = abi::__cxa_demangle(mangledName, nullptr, nullptr, &status);
51 
52  if(status == 0)
53  {
54  name = QString(unmangled);
55  free(unmangled);
56  }
57 #elif defined(_WIN32) && defined(NDEBUG)
58  char * const unmangled = __unDName(0, mangledName, 0, malloc, free, 0x2800);
59  if (unmangled)
60  {
61  QString unmangledName(unmangled);
62  name = unmangledName.split(' ', QString::SkipEmptyParts).back();
63  free(unmangled);
64  }
65 #else
66  name = name.split(' ', QString::SkipEmptyParts).back();
67 #endif
68  return name;
69 }
70 
71 #ifdef GetClassName
72 // clash with WinUser.h definition
73 #undef GetClassName
74 #endif
75 
76 QString GetClassName(const Object* obj)
77 {
78  return DemangleName(typeid(*const_cast<Object*>(obj)).name());
79 }
80 
81 TypeInfo::Concept::~Concept(){}
82 
83 template<>
84 struct TypeInfo::Model<EmptyType> : Concept {
85  QString GetName() const override { return QString(); }
86  QList<TypeInfo> GetSuperclasses() const override { return QList<TypeInfo>(); }
87 };
88 
90  : m_Self(std::make_shared<Model<EmptyType> >())
91 {
92 }
93 
94 bool TypeInfo::operator==(const TypeInfo& other) const
95 {
96  return this->GetName() == other.GetName();
97 }
98 
99 QString TypeInfo::GetName() const
100 {
101  return m_Self->GetName();
102 }
103 
104 QList<TypeInfo> TypeInfo::GetSuperclasses() const
105 {
106  return m_Self->GetSuperclasses();
107 }
108 
109 }
110 
111 }
QString GetClassName(const Object *obj)
bool operator==(const TypeInfo &other) const
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
STL namespace.
QString DemangleName(const char *mangledName)
QList< TypeInfo > GetSuperclasses() const