Skip to content

Commit

Permalink
update iguana
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Sep 6, 2024
1 parent b115dd0 commit b2e4b54
Show file tree
Hide file tree
Showing 38 changed files with 862 additions and 1,869 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct person {
std::string name;
int age;
};
REFLECTION(person, name, age);
YLT_REFL(person, name, age);
int main() {
person p{.name = "tom", .age = 20};
Expand All @@ -274,7 +274,7 @@ struct person {
std::string name;
int age;
};
REFLECTION(person, name, age);
YLT_REFL(person, name, age);

void basic_usage() {
std::string xml = R"(
Expand Down Expand Up @@ -308,7 +308,7 @@ struct person {
std::string name;
int age;
};
REFLECTION(person, name, age);
YLT_REFL(person, name, age);
void basic_usage() {
// serialization the structure to the string
Expand Down
4 changes: 2 additions & 2 deletions include/ylt/metric/counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ struct json_counter_metric_t {
std::map<std::string, std::string> labels;
std::variant<int64_t, double> value;
};
REFLECTION(json_counter_metric_t, labels, value);
YLT_REFL(json_counter_metric_t, labels, value);
struct json_counter_t {
std::string name;
std::string help;
std::string type;
std::vector<json_counter_metric_t> metrics;
};
REFLECTION(json_counter_t, name, help, type, metrics);
YLT_REFL(json_counter_t, name, help, type, metrics);
#endif

template <typename T, typename value_type>
Expand Down
4 changes: 2 additions & 2 deletions include/ylt/metric/histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ struct json_histogram_metric_t {
int64_t count;
double sum;
};
REFLECTION(json_histogram_metric_t, labels, quantiles, count, sum);
YLT_REFL(json_histogram_metric_t, labels, quantiles, count, sum);
struct json_histogram_t {
std::string name;
std::string help;
std::string type;
std::vector<json_histogram_metric_t> metrics;
};
REFLECTION(json_histogram_t, name, help, type, metrics);
YLT_REFL(json_histogram_t, name, help, type, metrics);
#endif

template <typename value_type>
Expand Down
4 changes: 2 additions & 2 deletions include/ylt/metric/summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct json_summary_metric_t {
int64_t count;
double sum;
};
REFLECTION(json_summary_metric_t, labels, quantiles, count, sum);
YLT_REFL(json_summary_metric_t, labels, quantiles, count, sum);
struct json_summary_t {
std::string name;
std::string help;
std::string type;
std::vector<json_summary_metric_t> metrics;
};
REFLECTION(json_summary_t, name, help, type, metrics);
YLT_REFL(json_summary_t, name, help, type, metrics);
#endif

struct block_t {
Expand Down
54 changes: 28 additions & 26 deletions include/ylt/reflection/user_reflect_macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@ struct member_traits<T Owner::*> {
template <class T>
using member_value_type_t = typename member_traits<T>::value_type;

#define YLT_REFL(STRUCT, ...) \
template <typename Visitor> \
inline static constexpr decltype(auto) refl_visit_members( \
STRUCT &t, Visitor &&visitor) { \
return visitor(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
template <typename Visitor> \
inline static constexpr decltype(auto) refl_visit_members( \
const STRUCT &t, Visitor &&visitor) { \
return visitor(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
inline static decltype(auto) refl_object_to_tuple(STRUCT &t) { \
return std::tie(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
inline static decltype(auto) refl_object_to_tuple(const STRUCT &t) { \
return std::tie(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
inline static constexpr decltype(auto) refl_member_names( \
const ylt::reflection::identity<STRUCT> &t) { \
constexpr std::array<std::string_view, YLT_ARG_COUNT(__VA_ARGS__)> arr{ \
WRAP_ARGS(CONCAT_NAME, t, ##__VA_ARGS__)}; \
return arr; \
} \
inline static constexpr std::size_t refl_member_count( \
const ylt::reflection::identity<STRUCT> &t) { \
return (std::size_t)YLT_ARG_COUNT(__VA_ARGS__); \
#define YLT_REFL(STRUCT, ...) \
template <typename Visitor> \
inline static constexpr decltype(auto) refl_visit_members( \
STRUCT &t, Visitor &&visitor) { \
return visitor(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
template <typename Visitor> \
inline static constexpr decltype(auto) refl_visit_members( \
const STRUCT &t, Visitor &&visitor) { \
return visitor(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
[[maybe_unused]] inline static decltype(auto) refl_object_to_tuple( \
STRUCT &t) { \
return std::tie(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
[[maybe_unused]] inline static decltype(auto) refl_object_to_tuple( \
const STRUCT &t) { \
return std::tie(WRAP_ARGS(CONCAT_MEMBER, t, ##__VA_ARGS__)); \
} \
[[maybe_unused]] inline static constexpr decltype(auto) refl_member_names( \
const ylt::reflection::identity<STRUCT> &t) { \
constexpr std::array<std::string_view, YLT_ARG_COUNT(__VA_ARGS__)> arr{ \
WRAP_ARGS(CONCAT_NAME, t, ##__VA_ARGS__)}; \
return arr; \
} \
[[maybe_unused]] inline static constexpr std::size_t refl_member_count( \
const ylt::reflection::identity<STRUCT> &t) { \
return (std::size_t)YLT_ARG_COUNT(__VA_ARGS__); \
}

template <typename T, typename Tuple, typename Visitor>
Expand Down
Loading

0 comments on commit b2e4b54

Please sign in to comment.