refl-cpp
refl.hpp File Reference
#include <stddef.h>
#include <cstring>
#include <array>
#include <memory>
#include <utility>
#include <optional>
#include <tuple>
#include <type_traits>
#include <ostream>
#include <sstream>
#include <iomanip>

Go to the source code of this file.

Classes

struct  refl::util::const_string< N >
 
struct  refl::util::type_list< Ts >
 
struct  refl::member::field
 
struct  refl::member::function
 
struct  refl::trait::remove_qualifiers< T >
 
struct  refl::trait::is_reflectable< T >
 
struct  refl::trait::is_container< T >
 
struct  refl::trait::get< size_t, typename >
 
struct  refl::trait::get< N, type_list< Ts... > >
 
struct  refl::trait::as_type_list< T >
 
struct  refl::trait::as_type_list< T< Ts... > >
 
struct  refl::trait::as_type_list< T >
 
struct  refl::trait::reverse< TypeList >
 
struct  refl::trait::concat< typename, typename >
 
struct  refl::trait::concat< type_list< Ts... >, type_list< Us... > >
 
struct  refl::trait::append< T, TypeList >
 
struct  refl::trait::prepend< T, TypeList >
 
struct  refl::trait::prepend< T, TypeList >
 
struct  refl::trait::filter< typename, typename >
 
struct  refl::trait::filter< Predicate, type_list< Ts... > >
 
struct  refl::trait::map< typename, typename >
 
struct  refl::trait::map< Mapper, type_list< Ts... > >
 
struct  refl::trait::is_instance< T >
 
struct  refl::trait::is_instance_of< T, U >
 
struct  refl::trait::contains< T, TypeList >
 
struct  refl::trait::contains_instance< T, TypeList >
 
struct  refl::trait::contains_base< T, TypeList >
 
struct  refl::attr::usage::type
 
struct  refl::attr::usage::function
 
struct  refl::attr::usage::field
 
struct  refl::attr::usage::member
 
struct  refl::attr::usage::any
 
class  refl::descriptor::type_descriptor< T >
 Represents a reflected type. More...
 
struct  refl::trait::is_member< T >
 
struct  refl::trait::is_field< T >
 
struct  refl::trait::is_function< T >
 
struct  refl::trait::is_type< T >
 
struct  refl::trait::is_descriptor< T >
 
class  refl::descriptor::member_descriptor_base< T, N >
 The base type for member descriptors. More...
 
class  refl::descriptor::field_descriptor< T, N >
 Represents a reflected field. More...
 
class  refl::descriptor::function_descriptor< T, N >
 Represents a reflected function. More...
 
class  refl::descriptor::type_descriptor< T >
 Represents a reflected type. More...
 
struct  refl::attr::property
 
struct  refl::attr::debug< F >
 
struct  refl::attr::base_types< Ts >
 
struct  refl::trait::is_property< T >
 
struct  refl::runtime::proxy< Derived, Target >
 A proxy object that has a static interface identical to the reflected functions and fields of the target. More...
 
struct  refl::trait::is_proxy< T >
 
struct  refl::trait::is_proxy< T >
 

Namespaces

 refl
 The top-level refl-cpp namespace It contains a few core refl-cpp namespaces and directly exposes core classes and functions.
 
 refl::util
 Contains utility types and functions for working with those types.
 
 refl::member
 Contains tag types denoting the different types of reflectable members.
 
 refl::trait
 Provides type-level operations for refl-cpp related use-cases.
 
 refl::attr
 Contains the definitions of the built-in attributes.
 
 refl::attr::usage
 Contains a number of constraints applicable to refl-cpp attributes.
 
 refl::descriptor
 Contains the basic reflection primitives as well as functions operating on those primitives.
 
 refl::runtime
 Contains utilities that can have runtime-overhead (like proxy, debug, invoke)
 

Macros

#define REFL_MAKE_CONST_STRING(CString)   (::refl::util::detail::copy_from_unsized<::refl::util::detail::strlen(CString)>(CString))
 
#define REFL_DETAIL_FORCE_EBO
 
#define REFL_DETAIL_STR_IMPL(...)   #__VA_ARGS__
 
#define REFL_DETAIL_STR(...)   REFL_DETAIL_STR_IMPL(__VA_ARGS__)
 
#define REFL_DETAIL_GROUP(...)   __VA_ARGS__
 
#define REFL_DETAIL_ATTRIBUTES(DeclType, ...)   static constexpr auto attributes{ ::refl::detail::make_attributes<::refl::attr::usage:: DeclType>(__VA_ARGS__) }; \
 
#define REFL_DETAIL_TYPE_BODY(TypeName, ...)
 
#define REFL_TYPE(TypeName, ...)
 
#define REFL_TEMPLATE(TemplateDeclaration, TypeName, ...)
 

Typedefs

template<typename T >
using refl::trait::remove_qualifiers_t = typename remove_qualifiers< T >::type
 
template<size_t N, typename TypeList >
using refl::trait::get_t = typename get< N, TypeList >::type
 
template<size_t N, typename TypeList >
using refl::trait::skip = detail::skip< N, TypeList >
 
template<size_t N, typename TypeList >
using refl::trait::skip_t = typename skip< N, TypeList >::type
 
template<typename T >
using refl::trait::as_type_list_t = typename as_type_list< T >::type
 
template<typename TypeList >
using refl::trait::first = get< 0, TypeList >
 
template<typename TypeList >
using refl::trait::first_t = typename first< TypeList >::type
 
template<typename TypeList >
using refl::trait::last = get< TypeList::size - 1, TypeList >
 
template<typename TypeList >
using refl::trait::last_t = typename last< TypeList >::type
 
template<typename TypeList >
using refl::trait::tail = skip< 1, TypeList >
 
template<typename TypeList >
using refl::trait::tail_t = typename tail< TypeList >::type
 
template<size_t N, typename TypeList >
using refl::trait::take = detail::take< type_list<>, N, TypeList >
 
template<size_t N, typename TypeList >
using refl::trait::take_t = typename take< N, TypeList >::type
 
template<typename TypeList >
using refl::trait::init = take< TypeList::size - 1, TypeList >
 
template<typename TypeList >
using refl::trait::init_t = typename init< TypeList >::type
 
template<typename TypeList >
using refl::trait::reverse_t = typename reverse< TypeList >::type
 
template<typename Lhs , typename Rhs >
using refl::trait::concat_t = typename concat< Lhs, Rhs >::type
 
template<typename T , typename TypeList >
using refl::trait::append_t = typename append< T, TypeList >::type
 
template<typename T , typename TypeList >
using refl::trait::prepend_t = typename prepend< T, TypeList >::type
 
template<template< typename > typename Predicate, typename TypeList >
using refl::trait::filter_t = typename filter< Predicate, TypeList >::type
 
template<template< typename > typename Mapper, typename... Ts>
using refl::trait::map_t = typename map< Mapper, Ts... >::type
 
template<typename T >
using refl::descriptor::member_list = decltype(detail::enumerate_members< T >(std::make_index_sequence< refl_impl::metadata::type_info__< T >::member_count >{}))
 

Functions

constexpr const_string< 0 > refl::util::make_const_string () noexcept
 
template<size_t N>
constexpr const_string< N - 1 > refl::util::make_const_string (const char(&str)[N]) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M > refl::util::operator+ (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M - 1 > refl::util::operator+ (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr const_string< N+M - 1 > refl::util::operator+ (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator== (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator!= (const const_string< N > &a, const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator== (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator!= (const const_string< N > &a, const char(&b)[M]) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator== (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N, size_t M>
constexpr bool refl::util::operator!= (const char(&a)[N], const const_string< M > &b) noexcept
 
template<size_t N>
constexpr std::ostream & refl::util::operator<< (std::ostream &os, const const_string< N > &str) noexcept
 
template<typename T >
constexpr bool refl::is_reflectable () noexcept
 
template<typename T >
constexpr bool refl::is_reflectable (const T &) noexcept
 
template<typename T >
constexpr type_descriptor< T > refl::reflect () noexcept
 
template<typename T >
constexpr type_descriptor< T > refl::reflect (const T &) noexcept
 
template<typename T = int, typename... Ts>
constexpr int refl::util::ignore (Ts &&...) noexcept
 
template<typename T >
constexpr decltype(auto) refl::util::identity (T &&t) noexcept
 
template<typename T >
constexpr const T & refl::util::make_const (const T &value) noexcept
 
template<typename T >
constexpr const T & refl::util::make_const (T &value) noexcept
 
template<typename T , typename... Ts>
constexpr std::array< T, sizeof...(Ts)> refl::util::to_array (const std::tuple< Ts... > &tuple) noexcept
 
template<typename T >
constexpr std::array< T, 0 > refl::util::to_array (const std::tuple<> &) noexcept
 
template<typename T , size_t N>
constexpr auto refl::util::to_tuple (const std::array< T, N > &array) noexcept
 
template<typename F , typename... Ts>
constexpr auto refl::util::map_to_tuple (type_list< Ts... > list, F &&f)
 
template<typename T , typename F , typename... Ts>
constexpr auto refl::util::map_to_array (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr void refl::util::for_each (type_list< Ts... > list, F &&f)
 
template<typename R , typename F , typename... Ts>
constexpr R refl::util::accumulate (type_list<>, F &&, R &&initial_value)
 
template<typename R , typename F , typename T , typename... Ts>
constexpr auto refl::util::accumulate (type_list< T, Ts... >, F &&f, R &&initial_value)
 
template<typename F , typename... Ts>
constexpr size_t refl::util::count_if (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto refl::util::filter (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto refl::util::find_first (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto refl::util::find_one (type_list< Ts... > list, F &&f)
 
template<typename F , typename... Ts>
constexpr auto refl::util::contains (type_list< Ts... > list, F &&f)
 
template<typename... Ts, typename F >
constexpr auto refl::util::apply (type_list< Ts... >, F &&f)
 
template<size_t N, typename... Ts>
constexpr auto & refl::util::get (std::tuple< Ts... > &ts) noexcept
 
template<size_t N, typename... Ts>
constexpr const auto & refl::util::get (const std::tuple< Ts... > &ts) noexcept
 
template<typename T , typename... Ts>
constexpr T & refl::util::get (std::tuple< Ts... > &ts) noexcept
 
template<typename T , typename... Ts>
constexpr const T & refl::util::get (const std::tuple< Ts... > &ts) noexcept
 
template<template< typename... > typename T, typename... Ts>
constexpr auto & refl::util::get_instance (std::tuple< Ts... > &ts) noexcept
 
template<template< typename... > typename T, typename... Ts>
constexpr const auto & refl::util::get_instance (const std::tuple< Ts... > &ts) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_field (const T) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_function (const T) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_type (const T) noexcept
 
template<typename A , typename T >
constexpr bool refl::descriptor::has_attribute (const T) noexcept
 
template<typename A , typename T >
constexpr const A & refl::descriptor::get_attribute (const T t) noexcept
 
template<template< typename... > typename A, typename T >
constexpr const auto & refl::descriptor::get_attribute (const T t) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_property (const T t) noexcept
 
template<typename T >
constexpr attr::property refl::descriptor::get_property (const T t) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_readable (const T) noexcept
 
template<typename T >
constexpr bool refl::descriptor::is_writable (const T) noexcept
 
template<typename T >
constexpr auto refl::descriptor::has_bases (const T t) noexcept
 
template<typename T >
constexpr auto refl::descriptor::get_bases (const T t) noexcept
 
template<typename T >
const char * refl::descriptor::get_debug_name (const T &t)
 
template<typename T >
const char * refl::descriptor::get_display_name (const T &t) noexcept
 
template<typename T >
void refl::runtime::debug (std::ostream &os, const T &value, bool compact=false)
 
template<typename T >
void refl::runtime::debug (std::ostream &os, const T &value, [[maybe_unused]] bool compact)
 
template<typename... Ts>
void refl::runtime::debug_all (std::ostream &os, const Ts &... values)
 
template<typename T >
std::string refl::runtime::debug_str (const T &value, bool compact=false)
 
template<typename... Ts>
std::string refl::runtime::debug_all_str (const Ts &... values)
 
template<typename U , typename T , typename... Args>
refl::runtime::invoke (T &&target, const char *name, Args &&... args)
 

Variables

template<typename T >
constexpr bool refl::trait::is_type_v { is_type<T>::value }
 

Macro Definition Documentation

◆ REFL_DETAIL_ATTRIBUTES

#define REFL_DETAIL_ATTRIBUTES (   DeclType,
  ... 
)    static constexpr auto attributes{ ::refl::detail::make_attributes<::refl::attr::usage:: DeclType>(__VA_ARGS__) }; \

Expands to the appropriate attributes static member variable. DeclType must be the name of one of the constraints defined in attr::usage. VA_ARGS is the list of attributes.

◆ REFL_DETAIL_FORCE_EBO

#define REFL_DETAIL_FORCE_EBO

◆ REFL_DETAIL_GROUP

#define REFL_DETAIL_GROUP (   ...)    __VA_ARGS__

Used to group input containing commas (e.g. template specializations with multiple types).

◆ REFL_DETAIL_STR

#define REFL_DETAIL_STR (   ...)    REFL_DETAIL_STR_IMPL(__VA_ARGS__)

Used to stringify input separated by commas (e.g. template specializations with multiple types).

◆ REFL_DETAIL_STR_IMPL

#define REFL_DETAIL_STR_IMPL (   ...)    #__VA_ARGS__

◆ REFL_DETAIL_TYPE_BODY

#define REFL_DETAIL_TYPE_BODY (   TypeName,
  ... 
)
Value:
typedef REFL_DETAIL_GROUP TypeName type; \
REFL_DETAIL_ATTRIBUTES(type, __VA_ARGS__) \
static constexpr auto name{ ::refl::util::make_const_string(REFL_DETAIL_STR(REFL_DETAIL_GROUP TypeName)) }; \
static constexpr size_t member_index_offset = __COUNTER__ + 1; \
template <size_t N, typename = void> \
struct member {};

Expands to the body of a type_info__ specialization.

◆ REFL_MAKE_CONST_STRING

#define REFL_MAKE_CONST_STRING (   CString)    (::refl::util::detail::copy_from_unsized<::refl::util::detail::strlen(CString)>(CString))

Converts a compile-time available const char* value to a const_string<N>. The argument must be a core constant expression and be null-terminated.

See also
refl::util::const_string

◆ REFL_TEMPLATE

#define REFL_TEMPLATE (   TemplateDeclaration,
  TypeName,
  ... 
)
Value:
namespace refl_impl::metadata { template <REFL_DETAIL_GROUP TemplateDeclaration> struct type_info__<REFL_DETAIL_GROUP TypeName> { \
REFL_DETAIL_TYPE_BODY(TypeName, __VA_ARGS__)

Creates reflection information for a specified type template. Takes an optional attribute list. TemplateDeclaration must be a panenthesis-enclosed list declaring the template parameters. (e.g. (typename A, typename B)). TypeName must be the fully-specialized type name and should also be enclosed in panenthesis. (e.g. (MyType<A, B>)) This macro must only be expanded in the global namespace.

Examples:

REFL_TEMPLATE((typename T), (std::vector<T>))
...
REFL_END

◆ REFL_TYPE

#define REFL_TYPE (   TypeName,
  ... 
)
Value:
namespace refl_impl::metadata { template<> struct type_info__<TypeName> { \
REFL_DETAIL_TYPE_BODY((TypeName), __VA_ARGS__)

Creates reflection information for a specified type. Takes an optional attribute list. This macro must only be expanded in the global namespace.

Examples:

REFL_TYPE(Point)
...
REFL_END
REFL_TEMPLATE
#define REFL_TEMPLATE(TemplateDeclaration, TypeName,...)
Definition: refl.hpp:2828
REFL_DETAIL_GROUP
#define REFL_DETAIL_GROUP(...)
Definition: refl.hpp:2779
REFL_DETAIL_STR
#define REFL_DETAIL_STR(...)
Definition: refl.hpp:2777
refl::util::make_const_string
constexpr const_string< N - 1 > make_const_string(const char(&str)[N]) noexcept
Definition: refl.hpp:227
REFL_TYPE
#define REFL_TYPE(TypeName,...)
Definition: refl.hpp:2811