Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
reflection.h
1#pragma once
2
3#include "sound_bakery/core/core_fwd.h"
4
5#include <rttr/registration_friend>
6#include <rttr/type>
7
8namespace sbk::reflection
9{
10 template <typename Target_Type, typename Source_Type>
11 Target_Type cast(Source_Type object)
12 {
13 static_assert(rttr::detail::pointer_count<Target_Type>::value == 1, "Target type must be a pointer");
14 static_assert(rttr::detail::pointer_count<Source_Type>::value == 1, "Source argument must be a pointer");
15 static_assert(rttr::detail::has_get_type_func<Source_Type>::value,
16 "Class has not type defined - please use the macro RTTR_ENABLE().");
17
18 using Return_Type = rttr::detail::remove_pointer_t<Target_Type>;
19 using Arg_Type = rttr::detail::remove_pointer_t<Source_Type>;
20
21 static_assert((std::is_volatile<Arg_Type>::value && std::is_volatile<Return_Type>::value) ||
22 (!std::is_volatile<Arg_Type>::value && std::is_volatile<Return_Type>::value) ||
23 (!std::is_volatile<Arg_Type>::value && !std::is_volatile<Return_Type>::value),
24 "Return type must have volatile qualifier");
25
26 static_assert((std::is_const<Arg_Type>::value && std::is_const<Return_Type>::value) ||
27 (!std::is_const<Arg_Type>::value && std::is_const<Return_Type>::value) ||
28 (!std::is_const<Arg_Type>::value && !std::is_const<Return_Type>::value),
29 "Return type must have const qualifier");
30
31 using source_type_no_cv = typename std::remove_cv<typename std::remove_pointer<Source_Type>::type>::type;
32 return static_cast<Target_Type>(rttr::type::apply_offset(const_cast<source_type_no_cv*>(object)->get_ptr(),
33 const_cast<source_type_no_cv*>(object)->get_type(),
34 Arg_Type::type()));
35 }
36
37 void registerReflectionTypes();
38 void unregisterReflectionTypes();
39} // namespace sbk::reflection