Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
flavor_macros.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
9// Macros for defining the flavor classes.
10// These are used to derive iterator methods along with the body of a 'flavor' class.
11// DEFINE_FLAVOR_MEMBERS lets you define a flavor entity as a collection of individual members, and derive an iterator.
12// while DEFINE_COMPOUND_GET_ALL lets you combine the iterators of substructures or base
13// classes.
14
18
19#include <tuple>
20#include <type_traits>
21
22namespace bb::detail {
23
24template <typename T, typename... BaseClass> constexpr std::size_t _sum_base_class_size(const T& arg)
25{
26 return (static_cast<const BaseClass&>(arg).size() + ...);
27}
28template <typename T, typename... BaseClass> auto _concatenate_base_class_get_all(T& arg)
29{
30 return concatenate(static_cast<BaseClass&>(arg).get_all()...);
31}
32template <typename T, typename... BaseClass> auto _concatenate_base_class_get_all_const(const T& arg)
33{
34 return concatenate(static_cast<const BaseClass&>(arg).get_all()...);
35}
36template <typename... BaseClass> auto _static_concatenate_base_class_get_labels()
37{
38 return concatenate(BaseClass::get_labels()...);
39}
40
41} // namespace bb::detail
42
43// Needed to force expansion of __VA_ARGS__ before converting to string.
44#define VARARGS_TO_STRING(...) #__VA_ARGS__
45
46#define DEFINE_REF_VIEW(...) \
47 [[nodiscard]] auto get_all() \
48 { \
49 return RefArray<std::remove_reference_t<DataType>, _members_size>{ __VA_ARGS__ }; \
50 } \
51 [[nodiscard]] auto get_all() const \
52 { \
53 return RefArray<const std::remove_reference_t<DataType>, _members_size>{ __VA_ARGS__ }; \
54 }
55
63#define DEFINE_FLAVOR_MEMBERS(DataType, ...) \
64 __VA_OPT__(DataType __VA_ARGS__;) \
65 static constexpr size_t _members_size = std::tuple_size_v<decltype(std::make_tuple(__VA_ARGS__))>; \
66 DEFINE_REF_VIEW(__VA_ARGS__) \
67 static const std::vector<std::string>& get_labels() \
68 { \
69 static const std::vector<std::string> labels = \
70 bb::detail::split_and_trim(VARARGS_TO_STRING(__VA_ARGS__), ','); \
71 return labels; \
72 } \
73 static constexpr std::size_t size() \
74 { \
75 return _members_size; \
76 }
77
78#define DEFINE_COMPOUND_GET_ALL(...) \
79 [[nodiscard]] auto get_all() \
80 { \
81 return bb::detail::_concatenate_base_class_get_all<decltype(*this), __VA_ARGS__>(*this); \
82 } \
83 [[nodiscard]] auto get_all() const \
84 { \
85 return bb::detail::_concatenate_base_class_get_all_const<decltype(*this), __VA_ARGS__>(*this); \
86 } \
87 constexpr std::size_t size() const \
88 { \
89 return bb::detail::_sum_base_class_size<decltype(*this), __VA_ARGS__>(*this); \
90 } \
91 static const std::vector<std::string>& get_labels() \
92 { \
93 static const auto labels = bb::detail::_static_concatenate_base_class_get_labels<__VA_ARGS__>(); \
94 return labels; \
95 }
auto _static_concatenate_base_class_get_labels()
auto _concatenate_base_class_get_all(T &arg)
constexpr std::size_t _sum_base_class_size(const T &arg)
auto _concatenate_base_class_get_all_const(const T &arg)
RefArray< T,(Ns+...)> constexpr concatenate(const RefArray< T, Ns > &... ref_arrays)
Concatenates multiple RefArray objects into a single RefArray.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13