1 /*=========================================================================
3 Module: $RCSfile: bbtkRTTI.cxx,v $
5 Date: $Date: 2009/05/28 08:12:06 $
6 Version: $Revision: 1.4 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 #include "bbtkMessageManager.h"
39 // Adapted from https://savannah.cern.ch/support/download.php?file_id=1972
41 // Something to which we can cast the void*s, to allow finding the
48 void* run_time_up_or_down_cast( const std::type_info& target_type,
49 const std::type_info& source_type,
50 const void* source_pointer
53 return run_time_up_or_down_cast(target_type,
55 const_cast<void*>(source_pointer));
58 void* run_time_up_or_down_cast( const std::type_info& target_type,
59 const std::type_info& source_type,
63 bbtkDebugMessage("data",5,
64 "run_time_up_or_down_cast : Casting pointer to '"
65 << TypeName(typeid(*(Dummy*)source_pointer))
66 << "' from " << TypeName(source_type)
67 << " to " << TypeName(target_type) << std::endl);
69 void* target_pointer = 0;
71 (__GNUC__ == 3 && (__GNUC_MINOR__ > 1 || \
72 (__GNUC_MINOR__ == 1 && \
73 __GNUC_PATCHLEVEL__ > 0)))
75 const abi::__class_type_info* targetTI =
76 (const abi::__class_type_info *)( &(target_type));
78 bbtkDebugMessage("data",7," * source = "<<source_pointer<<std::endl);
80 void* tmp = source_pointer;
81 if (source_type.__do_upcast(targetTI,&tmp))
87 bbtkDebugMessage("data",7,
88 " * upcast failed : trying dynamic down cast"
90 const abi::__class_type_info* sourceTI =
91 (const abi::__class_type_info *)( &(source_type));
94 target_pointer = abi::__dynamic_cast(source_pointer,
100 bbtkDebugMessage("data",7," * target = "<<target_pointer<<std::endl);
103 bbtkWarning("run_time_up_or_down_cast not impl. on Win : to do");
104 // target_pointer = __RTDynamicCast(source_pointer, 0, source_type, target_type, 0);
106 return target_pointer;