17 #ifndef AWALI_MISC_CAST_HH
18 # define AWALI_MISC_CAST_HH
23 # define down_cast static_cast
24 # define down_pointer_cast std::static_pointer_cast
31 ::awali::sttc::internal::down_caster(__FILE__, __LINE__).cast
32 #define down_pointer_cast down_cast
34 namespace awali {
namespace sttc {
48 template <
typename T,
typename U>
53 <<
file <<
':' <<
line <<
": " << msg
54 <<
" from " <<
typeid(U).name() <<
" to " <<
typeid(T).name()
59 template <
typename T,
typename U>
65 error<T, U>(
"down_casting nullptr");
66 T res =
dynamic_cast<const T
>(t);
68 error<T, U>(
"failed down_cast");
73 template <
typename T,
typename U>
79 error<std::shared_ptr<T>, std::shared_ptr<U>>(
"down_casting nullptr");
80 std::shared_ptr<T> res = std::dynamic_pointer_cast<T>(t);
82 error<std::shared_ptr<T>, std::shared_ptr<U>>(
"failed down_cast");
Main namespace of Awali.
Definition: ato.hh:22
A functor that captures the current location (to report errors), and provides "cast".
Definition: cast.hh:41
down_caster(const char *f, int l)
Definition: cast.hh:42
const char * file
Definition: cast.hh:45
void error(const char *msg)
Definition: cast.hh:50
T cast(U t)
Definition: cast.hh:62
int line
Definition: cast.hh:46
std::shared_ptr< T > cast(std::shared_ptr< U > t)
Special case for shared_ptr.
Definition: cast.hh:76