1#ifndef _BBM_REFLECTION_H_
2#define _BBM_REFLECTION_H_
136 namespace reflection {
141#define BBM_ATTRIBUTES(...) \
142 using attribute_tuple_t = bbm::named_cat_t< decltype(bbm::named_flatten(bbm::make_named<BBM_STRINGIFY_EACH(__VA_ARGS__)>(bbm::make_ref_tuple(__VA_ARGS__)))), typename reflection_base_t::attribute_tuple_t>; \
144 inline constexpr auto attribute_tuple(void) \
146 auto attr = bbm::named_flatten(bbm::make_named<BBM_STRINGIFY_EACH(__VA_ARGS__)>(bbm::make_ref_tuple(__VA_ARGS__))); \
147 return bbm::named_cat(attr, reflection_base_t::attribute_tuple(*this)); \
150 inline constexpr auto attribute_tuple(void) const \
152 auto attr = bbm::named_flatten(bbm::make_named<BBM_STRINGIFY_EACH(__VA_ARGS__)>(bbm::make_ref_tuple(__VA_ARGS__))); \
153 return bbm::named_cat(attr, reflection_base_t::attribute_tuple(*this)); \
161#define BBM_ATTRIBUTES_T std::conditional_t<attribute_tuple_t::size == 0, typename reflection_base_t::attribute_tuple_t, attribute_tuple_t>
166 template<
typename T>
struct attributes_impl
169 static inline constexpr auto value(T&&) {
return type{}; }
173 template<>
struct attributes_impl<void>
179 template<
typename T>
requires concepts::reflection::attributes<T>
180 struct attributes_impl<T>
182 using type =
typename std::decay_t<T>::attribute_tuple_t;
183 static inline constexpr auto value(T&& t) {
return t.attribute_tuple(); }
187 template<
typename T>
requires (concepts::reflection::basetypes<T> && !concepts::reflection::attributes<T>)
188 struct attributes_impl<T>
190 using type =
typename std::decay_t<T>::reflection_base_t::attribute_tuple_t;
191 static inline constexpr auto value(T&& t) {
return std::decay_t<T>::reflection_base_t::attribute_tuple(std::forward<T>(t)); }
202 return bbm::reflection::detail::attributes_impl<T>::value(std::forward<T>(t));
215#define BBM_BASETYPES(...) using reflection_base_t = bbm::reflection::detail::base_types<__VA_ARGS__>;
221 template<
string_literal N,
typename C>
struct prefix {};
228 template<
typename Cs>
231 using type = std::tuple<Cs>;
234 template<
typename C>
static inline constexpr auto attribute_tuple(C&) {
return attribute_tuple_t{}; }
238 template<
typename Cs>
requires (!concepts::reflection::attributes<Cs> && concepts::reflection::basetypes<Cs>)
241 using type = std::tuple<Cs>;
242 using attribute_tuple_t =
typename std::decay_t<Cs>::reflection_base_t::attribute_tuple_t;
245 static inline constexpr auto attribute_tuple(C& This)
247 return std::decay_t<Cs>::reflection_base::attribute_tuple(This);
252 template<
typename Cs>
requires concepts::reflection::attributes<Cs>
255 using type = std::tuple<Cs>;
259 static inline constexpr auto attribute_tuple(C& This)
267 template<
string_literal N,
typename Cs>
268 struct base_type<prefix<N, Cs>>
270 using type = std::tuple<typename base_type<Cs>::type>;
274 static inline constexpr auto attribute_tuple(C& This)
276 return bbm::prefix_names<N>( base_type<Cs>::attribute_tuple(This) );
281 template<
typename... Cs>
288 static inline constexpr auto attribute_tuple(C& This)
298 using type = std::tuple<>;
300 template<
typename C>
static inline constexpr auto attribute_tuple(C&) {
return attribute_tuple_t{}; }
308 template<
typename C>
struct basetypes_impl {
using type = std::tuple<>; };
311 struct basetypes_impl<C>
313 using type =
typename std::decay_t<C>::reflection_base_t::type;
322 using basetypes_t =
typename bbm::reflection::detail::basetypes_impl<C>::type;
332#define BBM_ENUM(FlagName, ...) \
333 template<> struct bbm::reflection::bbm_enum<FlagName> \
335 static constexpr auto values(void) \
337 using enum FlagName; \
338 return bbm::make_named<BBM_STRINGIFY_EACH(__VA_ARGS__)>( std::array{ __VA_ARGS__ } ); \
basetypes reflection allows to enumerate all base classes. The class has the following typename:
Definition: reflection.h:49
constexpr decltype(auto) attributes(T &&t)
Definition: reflection.h:200
static constexpr auto enum_v
Querry the names and values of an enum.
Definition: reflection.h:345
static constexpr size_t attributes_size
Definition: reflection.h:209
typename bbm::reflection::detail::attributes_impl< T >::type attributes_t
Definition: reflection.h:206
typename bbm::reflection::detail::basetypes_impl< C >::type basetypes_t
Definition: reflection.h:322
static constexpr size_t basetypes_size
Definition: reflection.h:325
Definition: reflection.h:18
Wrapper for adding a prefix to the attribute names of a base type.
Definition: reflection.h:221
Definition: aggregatebsdf.h:29
constexpr auto named_cat(T &&... t)
cat named types
Definition: named_util.h:40
decltype(prefix_names< PREFIX >(std::declval< T >())) prefix_names_t
type of named tuple with pre-fixed name.
Definition: named_util.h:108
decltype(named_cat(std::declval< T >()...)) named_cat_t
type of concatting multiple named tuples.
Definition: named_util.h:56
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20
decltype(std::tuple_cat(std::declval< Ts >()...)) tuple_cat_t
tuple_cat_t
Definition: tuple.h:81
named container
Definition: named.h:131
Extensions for the STL tuple class.
A wrapper for STL containers such as tuple, pair, and array. These containers force the programmer to...
bbm::reflection::detail::base_types<> reflection_base_t
Definition: reflection.h:354