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 /*=========================================================================
30 Module: $RCSfile: bbtkRTTI.h,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.7 $
34 =========================================================================*/
40 *\brief RTTI tools (system dependent).
43 #ifndef __BBTKRTTI_H_INCLUDED__
44 #define __BBTKRTTI_H_INCLUDED__
46 #include "bbtkSystem.h"
49 //-----------------------------------------------------------------------------
50 // RRTI type_info.name() demangling
51 // For type_info.name() demangling (gcc >= 3.1, see http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/namespaceabi.html)
52 // Test for GCC > 3.1.0 //
54 (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \
55 (__GNUC_MINOR__ == 1 && \
56 __GNUC_PATCHLEVEL__ > 0)))
61 inline std::string demangle_type_name(const char* name)
64 char* dem = abi::__cxa_demangle(name, 0, 0, &status);
65 std::string demangled(dem);
67 if (!status) return demangled;
73 #define BBTK_DEMANGLE_TYPE_NAME(NAME) bbtk::demangle_type_name(NAME)
75 //==========================================================================
78 //#include "Windows.h"
82 // include the right library in the linker stage
83 #pragma comment( lib, "imagehlp.lib" )
91 inline std::string demangle_type_name(const char* name)
94 if (UnDecorateSymbolName(name, demangled,
95 sizeof(name), UNDNAME_COMPLETE))
97 return name; //demangled;
105 #define BBTK_DEMANGLE_TYPE_NAME(NAME) bbtk::demangle_type_name(NAME)
109 #define BBTK_DEMANGLE_TYPE_NAME(NAME) NAME
112 #define BBTK_GET_CURRENT_OBJECT_NAME \
113 BBTK_DEMANGLE_TYPE_NAME(typeid(*this).name())
115 #define BBTK_GET_TYPE_NAME(A) \
116 BBTK_DEMANGLE_TYPE_NAME(typeid(A).name())
117 //-----------------------------------------------------------------------------
122 /// Template method which returns the name of a type
124 inline std::string TypeName()
125 { return BBTK_DEMANGLE_TYPE_NAME(typeid(T).name()); }
126 /// Template method which returns the name of the type of a variable
128 inline std::string TypeName(const T& t)
129 { return BBTK_DEMANGLE_TYPE_NAME(typeid(t).name()); }
130 /// Specialisation of TypeName when the type passed is already a type_info :
131 /// The user does not want to know the type of the type_info class but of
132 /// the class whose type_info is passed !
134 inline std::string TypeName<std::type_info>(const std::type_info& t)
135 { return BBTK_DEMANGLE_TYPE_NAME(t.name()); }
137 /// Template method which returns the human readable name of a type
139 inline std::string HumanTypeName()
140 { return TypeName<T>(); }
141 /// Template method which returns the human readable name of the type of a variable
143 inline std::string HumanTypeName(const T& t)
144 { return TypeName(t); }
145 /// Specialisation of TypeName when the type passed is already a type_info :
146 /// The user does not want to know the type of the type_info class but of
147 /// the class whose type_info is passed !
149 inline std::string HumanTypeName<std::type_info>(const std::type_info& t)
150 { return TypeName<std::type_info>(t); }
151 /// Macro to specialise the template function TypeName for certain types
152 /// (typically highly template types, such as STL types)
153 /// in order to return a **really** human readable string
154 #define BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(TYPE,NAME) \
155 template <> inline std::string HumanTypeName< TYPE >() \
157 template <> inline std::string HumanTypeName< TYPE >(const TYPE&) \
160 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(std::string,"String");
161 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(signed char,"Char");
162 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(signed short,"Short");
163 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(signed int,"Int");
164 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned char,"UChar");
165 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned short,"UShort");
166 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(unsigned int,"UInt");
167 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(float,"Float");
168 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(double,"Double");
169 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(bool,"Bool");
170 BBTK_DEFINE_HUMAN_READABLE_TYPE_NAME(long,"Long");
172 // Human readable strings for std::vector
173 #define BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(TYPE) \
174 template <> inline std::string HumanTypeName< std::vector<TYPE> >() \
175 { std::string t("Vector"); t += HumanTypeName<TYPE>(); return t;} \
176 template <> inline std::string HumanTypeName< std::vector<TYPE> > \
177 (const std::vector<TYPE>&) \
178 { std::string t("Vector"); t += HumanTypeName<TYPE>(); return t;}
180 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int8_t);
181 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint8_t);
182 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int16_t);
183 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint16_t);
184 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(int32_t);
185 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(uint32_t);
186 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(long);
187 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(float);
188 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(double);
189 BBTK_DEFINE_HUMAN_READABLE_VECTOR_TYPE_NAME(std::string);
191 /// The bbtk::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))
192 typedef const std::type_info& TypeInfo;
195 BBTK_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
196 const std::type_info& source_type,
199 BBTK_EXPORT void* run_time_up_or_down_cast( const std::type_info& target_type,
200 const std::type_info& source_type,
201 const void* source_pointer