File: cast.h

package info (click to toggle)
libwibble 0.1.9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 500 kB
  • ctags: 1,183
  • sloc: cpp: 5,760; sh: 113; makefile: 71
file content (31 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// -*- C++ -*-
#include <wibble/exception.h>
#ifndef WIBBLE_CAST_H
#define WIBBLE_CAST_H

namespace wibble {

template <typename T, typename X> T &downcast(X *v) {
    if (!v)
        throw exception::BadCastExt< X, T >( "downcast on null pointer" );
    T *x = dynamic_cast<T *>(v);
    if (!x)
        throw exception::BadCastExt< X, T >( "dynamic downcast failed" );
    return *x;
}

template< typename T >
typename T::WrappedType &unwrap( const T &x ) {
    return x.unwrap();
}

template< typename T >
T &unwrap( T &x ) { return x; }

template< typename _T, typename In > struct IsType {
    typedef _T T;
};

}

#endif