Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jul 24, 2023
1 parent eff2a5f commit 1c7f5c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct seed_or_index {

private:
static constexpr value_type MINUS_ONE =
std::numeric_limits<value_type>::max();
(std::numeric_limits<value_type>::max)();
static constexpr value_type HIGH_BIT = ~(MINUS_ONE >> 1);

value_type value_ = 0;
Expand Down Expand Up @@ -199,7 +199,7 @@ pmh_tables<M, Hash> constexpr make_pmh_tables(const carray<Item, N> &items,
carray<seed_or_index, M> 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<std::size_t>::max();
constexpr std::size_t UNUSED = (std::numeric_limits<std::size_t>::max)();
carray<std::size_t, M> H;
H.fill(UNUSED);

Expand Down
36 changes: 29 additions & 7 deletions iguana/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
#include <variant>
#include <vector>

#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 {
/******************************************/
Expand Down Expand Up @@ -560,9 +559,13 @@ namespace iguana::detail {
} \
using size_type = \
std::integral_constant<size_t, GET_ARG_COUNT(__VA_ARGS__)>; \
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<frozen::string, size_type::value> arr() { \
return arr_##STRUCT_NAME; \
Expand All @@ -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<frozen::string, N> 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__))

Expand Down Expand Up @@ -623,6 +629,10 @@ get_iguana_struct_map_impl(const std::array<frozen::string, sizeof...(Is)> &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<std::pair<std::string_view, std::string_view>>>
Expand All @@ -639,7 +649,8 @@ template <typename T> 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)

Expand Down Expand Up @@ -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__))});
Expand Down Expand Up @@ -798,6 +815,11 @@ template <typename T> constexpr const std::string_view get_name() {
return M::name();
}

template <typename T> constexpr const std::string_view get_fields() {
using M = Reflect_members<T>;
return M::fields();
}

template <typename T>
constexpr std::enable_if_t<is_reflection<T>::value, size_t> get_value() {
using M = decltype(iguana_reflect_members(std::declval<T>()));
Expand Down Expand Up @@ -891,4 +913,4 @@ constexpr std::enable_if_t<is_tuple<std::decay_t<T>>::value> for_each(T &&t,
std::make_index_sequence<SIZE>{});
}
} // namespace iguana
#endif // IGUANA_REFLECTION_HPP
#endif // IGUANA_REFLECTION_HPP

0 comments on commit 1c7f5c3

Please sign in to comment.