summaryrefslogtreecommitdiffhomepage
path: root/entity/metadata.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-19 18:31:08 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-19 18:31:08 +0100
commitcb665e2f6a829285f37abc72d03e434707f5af0d (patch)
tree3bebbdcc60ee26f15c2f9637e17f4e99e56b4f82 /entity/metadata.hpp
parentb0841e820860d09e0498554a43c01055e99baa57 (diff)
entity: get field data indirectly via a specialization
so now classes will be able to #ifdef including `entity/metadata.hpp` and specifying the fields without incurring an ODR violation.
Diffstat (limited to 'entity/metadata.hpp')
-rw-r--r--entity/metadata.hpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/entity/metadata.hpp b/entity/metadata.hpp
index 935f1792..0014f63c 100644
--- a/entity/metadata.hpp
+++ b/entity/metadata.hpp
@@ -15,6 +15,12 @@
#include <compat/function2.hpp>
#include <Corrade/Containers/StringView.h>
+namespace floormat::entities {
+
+template<typename T> struct entity_accessors;
+
+} // namespace floormat::entities
+
namespace floormat::entities::detail {
template<typename F, typename Tuple, std::size_t N>
@@ -46,7 +52,7 @@ constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple)
template<typename T> struct decay_tuple_;
template<typename... Ts> struct decay_tuple_<std::tuple<Ts...>> { using type = std::tuple<std::decay_t<Ts>...>; };
template<typename T> using decay_tuple = typename decay_tuple_<T>::type;
-template<typename T> struct accessors_for_ { using type = decay_tuple<std::decay_t<decltype(T::accessors())>>; };
+template<typename T> struct accessors_for_ { using type = decay_tuple<std::decay_t<decltype(entity_accessors<T>::accessors())>>; };
template<typename T> using accessors_for = typename accessors_for_<T>::type;
template<typename Obj, typename Type, typename Default, std::size_t I, typename... Fs> struct find_reader;
@@ -269,7 +275,7 @@ class entity_metadata final {
public:
static constexpr StringView class_name = name_of<T>;
static constexpr std::size_t size = std::tuple_size_v<entities::detail::accessors_for<T>>;
- static constexpr entities::detail::accessors_for<T> accessors = T::accessors();
+ static constexpr entities::detail::accessors_for<T> accessors = entities::entity_accessors<T>::accessors();
static constexpr auto erased_accessors = erased_helper(accessors);
};