Compile-time reflection of: More...
#include "util/tuple.h"#include "util/named.h"#include "util/macro_util.h"#include "util/string_literal.h"#include "concepts/reflection.h"Go to the source code of this file.
Classes | |
| struct | prefix< N, C > |
| Wrapper for adding a prefix to the attribute names of a base type. More... | |
Namespaces | |
| namespace | bbm |
| namespace | bbm::reflection |
Macros | |
| #define | BBM_ATTRIBUTES(...) |
| BBM_ATTRIBUTES macro for declaring the attriute of a class. | |
| #define | BBM_ATTRIBUTES_T std::conditional_t<attribute_tuple_t::size == 0, typename reflection_base_t::attribute_tuple_t, attribute_tuple_t> |
| BBM_ATTRIBUTES_T macro for robustly obtaining the type of the attributes tuple in unevaluated context. | |
| #define | BBM_BASETYPES(...) using reflection_base_t = bbm::reflection::detail::base_types<__VA_ARGS__>; |
| BaseTypes macro for declaring the base types/classes of a class. | |
| #define | BBM_ENUM(FlagName, ...) |
| BBM_ENUM macro for declaring the types of an enum. | |
Typedefs | |
| template<typename T > | |
| using | attributes_t = typename bbm::reflection::detail::attributes_impl< T >::type |
Global aliases. | |
Fallback for classes when no BaseTypes or Attributes are defined. The reason for a global alias is because decltype(*this) cannot be used in an unevaluated context (i.e., attribute_tuple_t in Attributes(...). | |
| using | reflection_base_t = bbm::reflection::detail::base_types<> |
| using | attribute_tuple_t = reflection_base_t::attribute_tuple_t |
Functions | |
| template<typename T > | |
| constexpr decltype(auto) | attributes (T &&t) |
Variables | |
| template<typename T > | |
| static constexpr size_t | attributes_size = std::tuple_size< attributes_t<T> >::value |
| template<typename T > | |
| static constexpr auto | enum_v = bbm_enum<std::decay_t<T>>::values() |
| Querry the names and values of an enum. | |
BaseTypes reflection methods | |
| template<typename C > | |
| using | basetypes_t = typename bbm::reflection::detail::basetypes_impl< C >::type |
| template<typename C > | |
| static constexpr size_t | basetypes_size = std::tuple_size< basetypes_t<C> >::value |
Compile-time reflection of:
To do:
Usage:
To add attribute reflection, add 'BBM_ATTRIBUTES(<attribute names...>)' after the declaration of the class attributes. For example:
We can then query the attributes, types, and number of attributes:
Note: we can also pass the attributes of an attribute; the name will be the names of the attributes of of the attribue:
To add public base class reflection, add 'BBM_BASETYPES(<base class names...>)' at the start of the class. For example:
To querry the type of the return type of attributes(...):
The difference between both (A and B) is that B requires an evaluated context (i.e., the type of the class must be known), whereas A is robust in unevaluated contexts (i.e., from inside the class before the class is complete).
We can query the base classes:
Querying the attributes will include the attributes of the base class too:
In some cases it might be desirable to prefix the attribute names of a base class:
BBM also support reflection for enum struct/classes.
See concepts/reflection.h for reflection related concepts.
| struct bbm::reflection::prefix |
Wrapper for adding a prefix to the attribute names of a base type.
| #define BBM_ATTRIBUTES | ( | ... | ) |
BBM_ATTRIBUTES macro for declaring the attriute of a class.
| #define BBM_ATTRIBUTES_T std::conditional_t<attribute_tuple_t::size == 0, typename reflection_base_t::attribute_tuple_t, attribute_tuple_t> |
BBM_ATTRIBUTES_T macro for robustly obtaining the type of the attributes tuple in unevaluated context.
| #define BBM_BASETYPES | ( | ... | ) | using reflection_base_t = bbm::reflection::detail::base_types<__VA_ARGS__>; |
BaseTypes macro for declaring the base types/classes of a class.
| #define BBM_ENUM | ( | FlagName, | |
| ... | |||
| ) |
BBM_ENUM macro for declaring the types of an enum.
| using reflection_base_t = bbm::reflection::detail::base_types<> |