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
6namespace wibble {
7
8template <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
17template< typename T >
18typename T::WrappedType &unwrap( const T &x ) {
19 return x.unwrap();
20}
21
22template< typename T >
23T &unwrap( T &x ) { return x; }
24
25template< typename _T, typename In > struct IsType {
26 typedef _T T;
27};
28
29}
30
31#endif
Definition amorph.h:17
T::WrappedType & unwrap(const T &x)
Definition cast.h:18
X::template Convert< T >::type & downcast(const X &a)
Definition amorph.h:413
Definition cast.h:25
_T T
Definition cast.h:26
Definition amorph.h:30
Definition exception.h:288