2 #include "bbtkMessageManager.h"
8 // Adapted from https://savannah.cern.ch/support/download.php?file_id=1972
10 // Something to which we can cast the void*s, to allow finding the
17 void* run_time_up_or_down_cast( const std::type_info& target_type,
18 const std::type_info& source_type,
19 const void* source_pointer
22 return run_time_up_or_down_cast(target_type,
24 const_cast<void*>(source_pointer));
27 void* run_time_up_or_down_cast( const std::type_info& target_type,
28 const std::type_info& source_type,
32 bbtkDebugMessage("Data",5,
33 "run_time_up_or_down_cast : Casting pointer to '"
34 << TypeName(typeid(*(Dummy*)source_pointer))
35 << "' from " << TypeName(source_type)
36 << " to " << TypeName(target_type) << std::endl);
38 void* target_pointer = 0;
40 (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \
41 (__GNUC_MINOR__ == 1 && \
42 __GNUC_PATCHLEVEL__ > 0)))
44 const abi::__class_type_info* targetTI =
45 (const abi::__class_type_info *)( &(target_type));
47 bbtkDebugMessage("Data",7," * source = "<<source_pointer<<std::endl);
49 void* tmp = source_pointer;
50 if (source_type.__do_upcast(targetTI,&tmp))
56 bbtkDebugMessage("Data",7,
57 " * upcast failed : trying dynamic down cast"
59 const abi::__class_type_info* sourceTI =
60 (const abi::__class_type_info *)( &(source_type));
63 target_pointer = abi::__dynamic_cast(source_pointer,
69 bbtkDebugMessage("Data",7," * target = "<<target_pointer<<std::endl);
72 bbtkWarning("run_time_up_or_down_cast not impl. on Win : to do");
73 // target_pointer = __RTDynamicCast(source_pointer, 0, source_type, target_type, 0);
75 return target_pointer;