Kùzu C++ API
Loading...
Searching...
No Matches
cast.h
Go to the documentation of this file.
1#pragma once
2
3#include <typeinfo>
4
5#include "assert.h"
6
7namespace kuzu {
8namespace common {
9
10template<typename TO, typename FROM>
11TO ku_dynamic_cast(FROM* old) {
12#if defined(KUZU_RUNTIME_CHECKS) || !defined(NDEBUG)
13 static_assert(std::is_pointer<TO>());
14 TO newVal = dynamic_cast<TO>(old);
15 KU_ASSERT(newVal != nullptr);
16 return newVal;
17#else
18 return reinterpret_cast<TO>(old);
19#endif
20}
21
22template<typename TO, typename FROM>
23TO ku_dynamic_cast(FROM& old) {
24#if defined(KUZU_RUNTIME_CHECKS) || !defined(NDEBUG)
25 static_assert(std::is_reference<TO>());
26 try {
27 TO newVal = dynamic_cast<TO>(old);
28 return newVal;
29 } catch (std::bad_cast& e) {
30 KU_ASSERT(false);
31 }
32#else
33 return reinterpret_cast<TO>(old);
34#endif
35}
36
37} // namespace common
38} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
TO ku_dynamic_cast(FROM *old)
Definition cast.h:11
Definition array_utils.h:7