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)))
62 inline std::string demangle_type_name(const char* name)
65 char* dem = abi::__cxa_demangle(name, 0, 0, &status);
66 std::string demangled(dem);
68 if (!status) return demangled;
74 #define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME)
76 //==========================================================================
79 //#include "Windows.h"
83 // include the right library in the linker stage
84 #pragma comment( lib, "imagehlp.lib" )
92 inline std::string demangle_type_name(const char* name)
95 if (UnDecorateSymbolName(name, demangled,
96 sizeof(name), UNDNAME_COMPLETE))
98 return name; //demangled;
106 #define CREA_DEMANGLE_TYPE_NAME(NAME) crea::demangle_type_name(NAME)
110 #define CREA_DEMANGLE_TYPE_NAME(NAME) NAME
113 #define CREA_GET_CURRENT_OBJECT_NAME \
114 CREA_DEMANGLE_TYPE_NAME(typeid(*this).name())
116 #define CREA_GET_TYPE_NAME(A) \
117 CREA_DEMANGLE_TYPE_NAME(typeid(A).name())
118 //-----------------------------------------------------------------------------
123 /// Template method which returns the name of a type
125 inline std::string TypeName()
126 { return CREA_DEMANGLE_TYPE_NAME(typeid(T).name()); }
127 /// Template method which returns the name of the type of a variable
129 inline std::string TypeName(const T& t)
130 { return CREA_DEMANGLE_TYPE_NAME(typeid(t).name()); }
131 /// Specialisation of TypeName when the type passed is already a type_info :
132 /// The user does not want to know the type of the type_info class but of
133 /// the class whose type_info is passed !
135 inline std::string TypeName<std::type_info>(const std::type_info& t)
136 { return CREA_DEMANGLE_TYPE_NAME(t.name()); }
138 /// Template method which returns the human readable name of a type
140 inline std::string HumanTypeName()
141 { return TypeName<T>(); }
142 /// Template method which returns the human readable name of the type of a variable
144 inline std::string HumanTypeName(const T& t)
145 { return TypeName(t); }
146 /// Specialisation of TypeName when the type passed is already a type_info :
147 /// The user does not want to know the type of the type_info class but of
148 /// the class whose type_info is passed !
150 inline std::string HumanTypeName<std::type_info>(const std::type_info& t)
151 { return TypeName<std::type_info>(t); }
152 /// Macro to specialise the template function TypeName for certain types
153 /// (typically highly template types, such as STL types)
154 /// in order to return a **really** human readable string
155 #define CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(TYPE,NAME) \
156 template <> inline std::string HumanTypeName< TYPE >() \
158 template <> inline std::string HumanTypeName< TYPE >(const TYPE&) \
161 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(std::string,"String");
162 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed char,"Char");
163 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed short,"Short");
164 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(signed int,"Int");
165 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned char,"UChar");
166 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned short,"UShort");
167 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned int,"UInt");
168 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(float,"Float");
169 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(double,"Double");
170 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(bool,"Bool");
171 CREA_DEFINE_HUMAN_READABLE_TYPE_NAME(long,"Long");
173 // Human readable strings for std::vector
174 #define CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(TYPE) \
175 template <> inline std::string HumanTypeName< std::vector<TYPE> >() \
176 { return "Vector"+HumanTypeName<TYPE>(); } \
177 template <> inline std::string HumanTypeName< std::vector<TYPE> > \
178 (const std::vector<TYPE>&) { return "Vector"+HumanTypeName<TYPE>(); }
181 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int8_t);
182 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint8_t);
183 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int16_t);
184 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint16_t);
185 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int32_t);
186 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint32_t);
187 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(long);
188 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(float);
189 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(double);
190 CREA_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(std::string);
192 /// 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))
193 typedef const std::type_info& TypeInfo;
196 CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
197 const std::type_info& source_type,
200 CREA_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
201 const std::type_info& source_type,
202 const void* source_pointer