From 1c7f5c391dcb3a3f72886e2d0cf8b9321883902c Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 24 Jul 2023 17:28:32 +0800 Subject: [PATCH] update --- frozen/bits/pmh.h | 4 ++-- iguana/reflection.hpp | 36 +++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/frozen/bits/pmh.h b/frozen/bits/pmh.h index 2ca3fc6c..20fccae3 100644 --- a/frozen/bits/pmh.h +++ b/frozen/bits/pmh.h @@ -137,7 +137,7 @@ struct seed_or_index { private: static constexpr value_type MINUS_ONE = - std::numeric_limits::max(); + (std::numeric_limits::max)(); static constexpr value_type HIGH_BIT = ~(MINUS_ONE >> 1); value_type value_ = 0; @@ -199,7 +199,7 @@ pmh_tables constexpr make_pmh_tables(const carray &items, carray G; // Default constructed to "index 0" // H becomes the second hash table in the resulting pmh function - constexpr std::size_t UNUSED = std::numeric_limits::max(); + constexpr std::size_t UNUSED = (std::numeric_limits::max)(); carray H; H.fill(UNUSED); diff --git a/iguana/reflection.hpp b/iguana/reflection.hpp index a8f0dbb9..4a224eb4 100644 --- a/iguana/reflection.hpp +++ b/iguana/reflection.hpp @@ -17,12 +17,11 @@ #include #include -#include "frozen/string.h" -#include "frozen/unordered_map.h" - #include "detail/itoa.hpp" #include "detail/string_stream.hpp" #include "detail/traits.hpp" +#include "frozen/string.h" +#include "frozen/unordered_map.h" namespace iguana::detail { /******************************************/ @@ -560,9 +559,13 @@ namespace iguana::detail { } \ using size_type = \ std::integral_constant; \ - constexpr static std::string_view name() { \ + constexpr static std::string_view name() { return name_##STRUCT_NAME; } \ + constexpr static std::string_view struct_name() { \ return std::string_view(#STRUCT_NAME, sizeof(#STRUCT_NAME) - 1); \ } \ + constexpr static std::string_view fields() { \ + return fields_##STRUCT_NAME; \ + } \ constexpr static size_t value() { return size_type::value; } \ constexpr static std::array arr() { \ return arr_##STRUCT_NAME; \ @@ -571,9 +574,12 @@ namespace iguana::detail { return reflect_members{}; \ } -#define MAKE_META_DATA(STRUCT_NAME, N, ...) \ +#define MAKE_META_DATA(STRUCT_NAME, TABLE_NAME, N, ...) \ constexpr inline std::array arr_##STRUCT_NAME = { \ MARCO_EXPAND(MACRO_CONCAT(CON_STR, N)(__VA_ARGS__))}; \ + constexpr inline std::string_view fields_##STRUCT_NAME = { \ + MAKE_NAMES(__VA_ARGS__)}; \ + constexpr inline std::string_view name_##STRUCT_NAME = TABLE_NAME; \ MAKE_META_DATA_IMPL(STRUCT_NAME, \ MAKE_ARG_LIST(N, &STRUCT_NAME::FIELD, __VA_ARGS__)) @@ -623,6 +629,10 @@ get_iguana_struct_map_impl(const std::array &arr, } // namespace iguana::detail namespace iguana { +#define REFLECTION_WITH_NAME(STRUCT_NAME, TABLE_NAME, ...) \ + MAKE_META_DATA(STRUCT_NAME, TABLE_NAME, GET_ARG_COUNT(__VA_ARGS__), \ + __VA_ARGS__) + inline std::unordered_map< std::string_view, std::vector>> @@ -639,7 +649,8 @@ template inline constexpr auto get_iguana_struct_map() { } #define REFLECTION(STRUCT_NAME, ...) \ - MAKE_META_DATA(STRUCT_NAME, GET_ARG_COUNT(__VA_ARGS__), __VA_ARGS__) + MAKE_META_DATA(STRUCT_NAME, #STRUCT_NAME, GET_ARG_COUNT(__VA_ARGS__), \ + __VA_ARGS__) #define REFLECTION_EMPTY(STRUCT_NAME) MAKE_META_DATA_EMPTY(STRUCT_NAME) @@ -700,6 +711,12 @@ inline int add_custom_fields(std::string_view key, return 0; } +#ifdef _MSC_VER +#define IGUANA_UNIQUE_VARIABLE(str) MACRO_CONCAT(str, __COUNTER__) +#else +#define IGUANA_UNIQUE_VARIABLE(str) MACRO_CONCAT(str, __LINE__) +#endif + #define CUSTOM_FIELDS_IMPL(STRUCT_NAME, N, ...) \ inline auto IGUANA_UNIQUE_VARIABLE(STRUCT_NAME) = iguana::add_custom_fields( \ #STRUCT_NAME, {MARCO_EXPAND(MACRO_CONCAT(CON_STR, N)(__VA_ARGS__))}); @@ -798,6 +815,11 @@ template constexpr const std::string_view get_name() { return M::name(); } +template constexpr const std::string_view get_fields() { + using M = Reflect_members; + return M::fields(); +} + template constexpr std::enable_if_t::value, size_t> get_value() { using M = decltype(iguana_reflect_members(std::declval())); @@ -891,4 +913,4 @@ constexpr std::enable_if_t>::value> for_each(T &&t, std::make_index_sequence{}); } } // namespace iguana -#endif // IGUANA_REFLECTION_HPP \ No newline at end of file +#endif // IGUANA_REFLECTION_HPP