OGS
ReflectionData.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <string>
14#include <tuple>
15
17{
26template <typename Class, typename Accessor>
28{
29 static_assert(std::is_same_v<Accessor, std::remove_cvref_t<Accessor>>);
30 static_assert(std::is_invocable_v<Accessor, Class&>);
31 static_assert(std::is_invocable_v<Accessor, Class const&>);
32 static_assert(
33 std::is_lvalue_reference_v<std::invoke_result_t<Accessor, Class&>>);
34 static_assert(std::is_lvalue_reference_v<
35 std::invoke_result_t<Accessor, Class const&>>);
36
37 ReflectionData(std::string name, Accessor&& accessor)
38 : name(std::move(name)), accessor(std::move(accessor))
39 {
40 }
41
42 explicit ReflectionData(Accessor&& accessor) : accessor(std::move(accessor))
43 {
44 }
45
46 std::string name;
47 Accessor accessor;
48};
49
50template <typename Class, typename Accessor>
51auto makeReflectionData(Accessor&& accessor)
52{
54 std::forward<Accessor>(accessor)};
55}
56
57template <typename Class, typename Accessor>
58auto makeReflectionData(std::string name, Accessor&& accessor)
59{
61 std::move(name), std::forward<Accessor>(accessor)};
62}
63
64template <typename Class, typename Member>
65auto makeReflectionData(Member Class::*member)
66{
67 return makeReflectionData<Class>([member](auto& obj) -> auto&
68 { return obj.*member; });
69}
70
71template <typename Class, typename Member>
72auto makeReflectionData(std::string name, Member Class::*member)
73{
75 std::move(name), [member](auto& obj) -> auto& { return obj.*member; });
76}
77
78template <typename Class, typename Member>
79auto reflectWithName(std::string name, Member Class::*member)
80{
81 return std::tuple{makeReflectionData(std::move(name), member)};
82}
83
84template <typename Class, typename... Accessors>
85auto reflectWithoutName(Accessors&&... accessors)
86{
87 return std::tuple{
88 makeReflectionData<Class>(std::forward<Accessors>(accessors))...};
89}
90
91template <typename Class, typename... Members>
92auto reflectWithoutName(Members Class::*... members)
93{
94 return std::tuple{makeReflectionData<Class>(members)...};
95}
96} // namespace ProcessLib::Reflection
auto reflectWithName(std::string name, Member Class::*member)
auto makeReflectionData(Accessor &&accessor)
auto reflectWithoutName(Accessors &&... accessors)
ReflectionData(std::string name, Accessor &&accessor)