2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
28 /*=========================================================================
31 Module: $RCSfile: creaRTTI.h,v $
33 Date: $Date: 2012/11/15 10:43:26 $
34 Version: $Revision: 1.4 $
36 =========================================================================*/
39 *\brief RTTI tools (system dependent).
42 #ifndef __CREARTTI_H_INCLUDED__
43 #define __CREARTTI_H_INCLUDED__
45 #include "creaSystem.h"
48 //-----------------------------------------------------------------------------
49 // RRTI type_info.name() demangling
50 // For type_info.name() demangling (gcc >= 3.1, see http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/namespaceabi.html)
51 // Test for GCC > 3.1.0 //
53 (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \
54 (__GNUC_MINOR__ == 1 && \
55 __GNUC_PATCHLEVEL__ > 0)))
60 inline std::string demangle_type_name(const char* name)
63 char* dem = abi::__cxa_demangle(name, 0, 0, &status);
64 std::string demangled(dem);
66 if (!status) return demangled;
72 #define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME)
74 //==========================================================================
77 //#include "Windows.h"
81 // include the right library in the linker stage
82 #pragma comment( lib, "imagehlp.lib" )
90 inline std::string demangle_type_name(const char* name)
93 if (UnDecorateSymbolName(name, demangled,
94 sizeof(name), UNDNAME_COMPLETE))
96 return name; //demangled;
104 #define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME)
108 #define CREA_DEMANGLE_TYPE_NAME(NAME) NAME
111 #define CREA_GET_CURRENT_OBJECT_NAME \
112 CREA_DEMANGLE_TYPE_NAME(typeid(*this).name())
114 #define CREA_GET_TYPE_NAME(A) \
115 CREA_DEMANGLE_TYPE_NAME(typeid(A).name())
116 //-----------------------------------------------------------------------------
121 /// Template method which returns the name of a type
123 inline std::string TypeName()
124 { return CREA_DEMANGLE_TYPE_NAME(typeid(T).name()); }
125 /// Template method which returns the name of the type of a variable
127 inline std::string TypeName(const T& t)
128 { return CREA_DEMANGLE_TYPE_NAME(typeid(t).name()); }
129 /// Specialisation of TypeName when the type passed is already a type_info :
130 /// The user does not want to know the type of the type_info class but of
131 /// the class whose type_info is passed !
133 inline std::string TypeName<std::type_info>(const std::type_info& t)
134 { return CREA_DEMANGLE_TYPE_NAME(t.name()); }
136 /// Template method which returns the human readable name of a type
138 inline std::string HumanTypeName()
139 { return TypeName<T>(); }
140 /// Template method which returns the human readable name of the type of a variable
142 inline std::string HumanTypeName(const T& t)
143 { return TypeName(t); }
144 /// Specialisation of TypeName when the type passed is already a type_info :
145 /// The user does not want to know the type of the type_info class but of
146 /// the class whose type_info is passed !
148 inline std::string HumanTypeName<std::type_info>(const std::type_info& t)
149 { return TypeName<std::type_info>(t); }
150 /// Macro to specialise the template function TypeName for certain types
151 /// (typically highly template types, such as STL types)
152 /// in order to return a **really** human readable string
153 #define CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(TYPE,NAME) \
154 template <> inline std::string HumanTypeName< TYPE >() \
156 template <> inline std::string HumanTypeName< TYPE >(const TYPE&) \
159 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(std::string,"String");
160 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed char,"Char");
161 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed short,"Short");
162 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed int,"Int");
163 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned char,"UChar");
164 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned short,"UShort");
165 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned int,"UInt");
166 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(float,"Float");
167 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(double,"Double");
168 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(bool,"Bool");
169 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(long,"Long");
171 // Human readable strings for std::vector
172 #define CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(TYPE) \
173 template <> inline std::string HumanTypeName< std::vector<TYPE> >() \
174 { return "Vector"+HumanTypeName<TYPE>(); } \
175 template <> inline std::string HumanTypeName< std::vector<TYPE> > \
176 (const std::vector<TYPE>&) { return "Vector"+HumanTypeName<TYPE>(); }
179 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int8_t);
180 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint8_t);
181 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int16_t);
182 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint16_t);
183 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int32_t);
184 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint32_t);
185 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(long);
186 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(float);
187 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(double);
188 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(std::string);
190 /// The crea::TypeInfo type is a const ref on std::type_info (which can only be manipulated as such (because typeid returns const std::type_info& and type_info has all constructors private))
191 typedef const std::type_info& TypeInfo;
194 CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
195 const std::type_info& source_type,
198 CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
199 const std::type_info& source_type,
200 const void* source_pointer