wibble  1.1
cast.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #include <wibble/exception.h>
3 #ifndef WIBBLE_CAST_H
4 #define WIBBLE_CAST_H
5 
6 namespace wibble {
7 
8 template <typename T, typename X> T &downcast(X *v) {
9  if (!v)
10  throw exception::BadCastExt< X, T >( "downcast on null pointer" );
11  T *x = dynamic_cast<T *>(v);
12  if (!x)
13  throw exception::BadCastExt< X, T >( "dynamic downcast failed" );
14  return *x;
15 }
16 
17 template< typename T >
18 typename T::WrappedType &unwrap( const T &x ) {
19  return x.unwrap();
20 }
21 
22 template< typename T >
23 T &unwrap( T &x ) { return x; }
24 
25 template< typename _T, typename In > struct IsType {
26  typedef _T T;
27 };
28 
29 }
30 
31 #endif
Definition: amorph.h:17
X::template Convert< T >::type & downcast(const X &a)
Definition: amorph.h:413
T::WrappedType & unwrap(const T &x)
Definition: cast.h:18
Definition: cast.h:25
_T T
Definition: cast.h:26
Definition: exception.h:288