wibble
0.1.28
|
00001 // -*- C++ -*- 00002 #include <wibble/exception.h> 00003 #ifndef WIBBLE_CAST_H 00004 #define WIBBLE_CAST_H 00005 00006 namespace wibble { 00007 00008 template <typename T, typename X> T &downcast(X *v) { 00009 if (!v) 00010 throw exception::BadCastExt< X, T >( "downcast on null pointer" ); 00011 T *x = dynamic_cast<T *>(v); 00012 if (!x) 00013 throw exception::BadCastExt< X, T >( "dynamic downcast failed" ); 00014 return *x; 00015 } 00016 00017 template< typename T > 00018 typename T::WrappedType &unwrap( const T &x ) { 00019 return x.unwrap(); 00020 } 00021 00022 template< typename T > 00023 T &unwrap( T &x ) { return x; } 00024 00025 template< typename _T, typename In > struct IsType { 00026 typedef _T T; 00027 }; 00028 00029 } 00030 00031 #endif