inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/cast
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_cast
00005 #define inlib_cast
00006 
00007 #if defined(__linux) || defined(ANDROID_NDK)
00008 // Python shell (2.3.3) looses the dynamic_cast on the DLL modules !
00009 // Then we stay with our "safe cast".
00010 #define INLIB_CAST(a__obj,a__cls) (a__cls*)(a__obj).cast(#a__cls)
00011 #define INLIB_CONST_CAST(a__obj,a__cls) (const a__cls*)(a__obj).cast(#a__cls)
00012 #else
00013 #define INLIB_CAST(a__obj,a__cls) dynamic_cast<a__cls*>(&a__obj)
00014 #define INLIB_CONST_CAST(a__obj,a__cls) dynamic_cast<const a__cls*>(&a__obj)
00015 #endif
00016 
00017 #define INLIB_SAFE_CAST(a__obj,a__cls) (a__cls*)(a__obj).cast(#a__cls)
00018 
00019 // Used in implementations of interfaces cast methods.
00020 #define INLIB_SCAST(a__cls) (void*)static_cast<const a__cls*>(this)
00021 
00022 #define INLIB_IF_CAST(a__cls) \
00023   if(a_class==#a__cls) {return (void*)static_cast<const a__cls*>(this);}
00024 
00025 // To break const :
00026 #define INLIB_SELF(a__cls) a__cls& self = const_cast<a__cls&>(*this)
00027 
00028 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines