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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
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
19
20#include <array>
21#include <iostream>
22#include <sstream>
23#include <tuple>
24#include <type_traits>
25
26namespace bb::detail {
27
28template <typename T, typename... BaseClass> constexpr std::size_t _sum_base_class_size(const T& arg)
29{
30 return (static_cast<const BaseClass&>(arg).size() + ...);
31}
32template <typename T, typename... BaseClass> auto _concatenate_base_class_get_all(T& arg)
33{
34 return concatenate(static_cast<BaseClass&>(arg).get_all()...);
35}
36template <typename T, typename... BaseClass> auto _concatenate_base_class_get_all_const(const T& arg)
37{
38 return concatenate(static_cast<const BaseClass&>(arg).get_all()...);
39}
40template <typename... BaseClass> auto _static_concatenate_base_class_get_labels()
41{
42 return concatenate(BaseClass::get_labels()...);
43}
44
45} // namespace bb::detail
46
47// Needed to force expansion of __VA_ARGS__ before converting to string.
48#define VARARGS_TO_STRING(...) #__VA_ARGS__
49
50#define DEFINE_REF_VIEW(...) \
51 [[nodiscard]] auto get_all() \
52 { \
53 return RefArray<std::remove_reference_t<DataType>, _members_size>{ __VA_ARGS__ }; \
54 } \
55 [[nodiscard]] auto get_all() const \
56 { \
57 return RefArray<const std::remove_reference_t<DataType>, _members_size>{ __VA_ARGS__ }; \
58 }
59
67#define DEFINE_FLAVOR_MEMBERS(DataType, ...) \
68 __VA_OPT__(DataType __VA_ARGS__;) \
69 static constexpr size_t _members_size = std::tuple_size_v<decltype(std::make_tuple(__VA_ARGS__))>; \
70 DEFINE_REF_VIEW(__VA_ARGS__) \
71 static const std::vector<std::string>& get_labels() \
72 { \
73 static const std::vector<std::string> labels = \
74 bb::detail::split_and_trim(VARARGS_TO_STRING(__VA_ARGS__), ','); \
75 return labels; \
76 } \
77 static constexpr std::size_t size() \
78 { \
79 return _members_size; \
80 }
81
82#define DEFINE_COMPOUND_GET_ALL(...) \
83 [[nodiscard]] auto get_all() \
84 { \
85 return bb::detail::_concatenate_base_class_get_all<decltype(*this), __VA_ARGS__>(*this); \
86 } \
87 [[nodiscard]] auto get_all() const \
88 { \
89 return bb::detail::_concatenate_base_class_get_all_const<decltype(*this), __VA_ARGS__>(*this); \
90 } \
91 constexpr std::size_t size() const \
92 { \
93 return bb::detail::_sum_base_class_size<decltype(*this), __VA_ARGS__>(*this); \
94 } \
95 static const std::vector<std::string>& get_labels() \
96 { \
97 static const auto labels = bb::detail::_static_concatenate_base_class_get_labels<__VA_ARGS__>(); \
98 return labels; \
99 }
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