|
@@ -10,9 +10,9 @@
|
|
|
#include "reflection/object.h"
|
|
#include "reflection/object.h"
|
|
|
#include "reflection/proxy.h"
|
|
#include "reflection/proxy.h"
|
|
|
|
|
|
|
|
-#define REFLECTION(expr) \
|
|
|
|
|
|
|
+#define REFLECTION_F(expr) \
|
|
|
[=](Obj & obj, std::string name) { return Object(expr, std::move(name)); }
|
|
[=](Obj & obj, std::string name) { return Object(expr, std::move(name)); }
|
|
|
-#define CONST_REFLECTION(expr) \
|
|
|
|
|
|
|
+#define CONST_REFLECTION_F(expr) \
|
|
|
[=](Obj const & obj, std::string name) { \
|
|
[=](Obj const & obj, std::string name) { \
|
|
|
return Object(expr, std::move(name)); \
|
|
return Object(expr, std::move(name)); \
|
|
|
}
|
|
}
|
|
@@ -21,7 +21,8 @@ namespace reflection {
|
|
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
constexpr auto is_final_reflection =
|
|
constexpr auto is_final_reflection =
|
|
|
- std::is_same_v<T, std::string> || std::is_fundamental_v<T> || std::is_enum_v<T>;
|
|
|
|
|
|
|
+ std::is_same_v<T, std::string> || std::is_fundamental_v<T> ||
|
|
|
|
|
+ std::is_enum_v<T>;
|
|
|
|
|
|
|
|
template <typename Obj, typename> class Reflection {
|
|
template <typename Obj, typename> class Reflection {
|
|
|
public:
|
|
public:
|
|
@@ -45,70 +46,38 @@ public:
|
|
|
Reflection & bind(std::string_view id, R (Obj::*get)() const,
|
|
Reflection & bind(std::string_view id, R (Obj::*get)() const,
|
|
|
void (Obj::*set)(I)) {
|
|
void (Obj::*set)(I)) {
|
|
|
using V = std::decay_t<R>;
|
|
using V = std::decay_t<R>;
|
|
|
- members_.emplace(id, REFLECTION(Proxy<V>(obj, get, set)));
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION((obj.*get)()));
|
|
|
|
|
|
|
+ members_.emplace(id, REFLECTION_F(Proxy<V>(obj, get, set)));
|
|
|
|
|
+ const_members_.emplace(id, CONST_REFLECTION_F((obj.*get)()));
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
template <typename R>
|
|
template <typename R>
|
|
|
Reflection & bind(std::string_view id, R (Obj::*get)() const,
|
|
Reflection & bind(std::string_view id, R (Obj::*get)() const,
|
|
|
- std::decay_t<R> &(Obj::*acc)()) {
|
|
|
|
|
- members_.emplace(id, REFLECTION((obj.*acc)()));
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION((obj.*get)()));
|
|
|
|
|
|
|
+ std::decay_t<R> & (Obj::*acc)()) {
|
|
|
|
|
+ members_.emplace(id, REFLECTION_F((obj.*acc)()));
|
|
|
|
|
+ const_members_.emplace(id, CONST_REFLECTION_F((obj.*get)()));
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
Reflection & bind(std::string_view id, T (Obj::*get)() const) {
|
|
Reflection & bind(std::string_view id, T (Obj::*get)() const) {
|
|
|
- const_members_.emplace(id, CONST_REFLECTION((obj.*get)()));
|
|
|
|
|
|
|
+ const_members_.emplace(id, CONST_REFLECTION_F((obj.*get)()));
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template <typename T> Reflection & bind(std::string_view id, T Obj::*member) {
|
|
template <typename T> Reflection & bind(std::string_view id, T Obj::*member) {
|
|
|
- members_.emplace(id, REFLECTION(obj.*member));
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION(obj.*member));
|
|
|
|
|
|
|
+ members_.emplace(id, REFLECTION_F(obj.*member));
|
|
|
|
|
+ const_members_.emplace(id, CONST_REFLECTION_F(obj.*member));
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template <typename F> Reflection & bind(std::string_view id, F func) {
|
|
template <typename F> Reflection & bind(std::string_view id, F func) {
|
|
|
if constexpr (!std::is_const_v<decltype(func(std::declval<Obj &>()))>) {
|
|
if constexpr (!std::is_const_v<decltype(func(std::declval<Obj &>()))>) {
|
|
|
- members_.emplace(id, REFLECTION(func(obj)));
|
|
|
|
|
- } else {
|
|
|
|
|
- members_.emplace(id, CONST_REFLECTION(func(obj)));
|
|
|
|
|
- }
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION(func(obj)));
|
|
|
|
|
- return *this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename R, typename T>
|
|
|
|
|
- Reflection & bind(std::string_view id, T Obj::*member) {
|
|
|
|
|
- if constexpr (std::is_convertible_v<T, R>) {
|
|
|
|
|
- return bind(id, member, [](T const &v) { return static_cast<R>(v); });
|
|
|
|
|
|
|
+ members_.emplace(id, REFLECTION_F(func(obj)));
|
|
|
} else {
|
|
} else {
|
|
|
- return bind(id, member, TypeConversion<R, T>());
|
|
|
|
|
|
|
+ members_.emplace(id, CONST_REFLECTION_F(func(obj)));
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename R, typename T>
|
|
|
|
|
- Reflection & bind(std::string_view id, T (Obj::*get)() const) {
|
|
|
|
|
- if constexpr (std::is_convertible_v<T, R>) {
|
|
|
|
|
- return bind(id, get, [](T const &v) { return static_cast<R>(v); });
|
|
|
|
|
- } else {
|
|
|
|
|
- return bind(id, get, TypeConversion<R, T>());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename T, typename F>
|
|
|
|
|
- Reflection & bind(std::string_view id, T Obj::*member, F convert) {
|
|
|
|
|
- members_.emplace(id, CONST_REFLECTION(convert(obj.*member)));
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION(convert(obj.*member)));
|
|
|
|
|
- return *this;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename T, typename F>
|
|
|
|
|
- Reflection & bind(std::string_view id, T (Obj::*get)() const, F convert) {
|
|
|
|
|
- members_.emplace(id, CONST_REFLECTION(convert((obj.*get)())));
|
|
|
|
|
- const_members_.emplace(id, CONST_REFLECTION(convert((obj.*get)())));
|
|
|
|
|
|
|
+ const_members_.emplace(id, CONST_REFLECTION_F(func(obj)));
|
|
|
return *this;
|
|
return *this;
|
|
|
}
|
|
}
|
|
|
|
|
|