MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Describe.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @def MF_DESCRIBE(Type)
5 * @brief Requests a generated member description for a struct at namespace scope.
6 *
7 * Place it on its own line after the complete definition, and include the
8 * header's generated sidecar (Name.describe.hpp) once after the last request.
9 * The mayaflux_reflect tool reads the request and writes
10 * MayaFlux::Reflect::Generated::Description<Type> into that sidecar. In
11 * ordinary compilation the macro expands to nothing.
12 */
13#ifndef MF_DESCRIBE
14#define MF_DESCRIBE(...)
15#endif
16
17/**
18 * @def MF_DESCRIBE_FUNCTION(Function)
19 * @brief Requests the parameter names of a function at namespace scope.
20 *
21 * Name the function as an expression: &Geometry::horizontal_fader, an explicit
22 * specialization such as &drag_with<float>, or a cast that picks one overload.
23 * Include the header's generated sidecar (Name.signatures.hpp) once after the
24 * last request. The mayaflux_signatures tool reads the request in its functions
25 * mode and writes MayaFlux::Reflect::Generated::Signature<Function> into that
26 * sidecar. In ordinary compilation the macro expands to nothing.
27 */
28#ifndef MF_DESCRIBE_FUNCTION
29#define MF_DESCRIBE_FUNCTION(...)
30#endif
31
33
34template <typename T>
36
37template <auto Pointer>
38struct Member;
39
40/**
41 * @struct Signature
42 * @brief The parameter names of a described function, which C++ cannot supply itself.
43 *
44 * A generated specialization holds name, required (how many leading parameters
45 * have no default, so a call needs at least that many arguments), parameters
46 * (every parameter name in order) and call<K>(values), which calls the function
47 * by name with the first K elements of a tuple. The call is by name and not
48 * through Function so the function's own default arguments apply to the ones
49 * left out. The parameter types come from the function's own type.
50 */
51template <auto Function>
52struct Signature;
53
54/**
55 * @struct Member
56 * @brief One described data member: its name and its member pointer.
57 *
58 * Owner is the class that declares the member, which may be a base of the
59 * described type.
60 */
61template <typename Owner, typename Value, Value Owner::* Pointer>
62struct Member<Pointer> {
63 using owner_type = Owner;
64 using value_type = Value;
65
66 std::string_view name;
67
68 static constexpr auto pointer = Pointer;
69
70 constexpr decltype(auto) get(Owner& object) const { return object.*Pointer; }
71 constexpr decltype(auto) get(const Owner& object) const { return object.*Pointer; }
72};
73
74}
75
76namespace MayaFlux::Reflect {
77
78/**
79 * @concept Described
80 * @brief A type whose generated sidecar defines Generated::Description<T>::members().
81 *
82 * The sidecar of a header is included after its namespaces close, so code in the
83 * same header that sits before that include does not see the description.
84 */
85template <typename T>
86concept Described = requires { Generated::Description<std::remove_cv_t<T>>::members(); };
87
88/**
89 * @concept DescribedFunction
90 * @brief A function pointer whose generated sidecar defines Generated::Signature<Function>.
91 */
92template <auto Function>
94
95}
A function pointer whose generated sidecar defines Generated::Signature<Function>.
Definition Describe.hpp:93
A type whose generated sidecar defines Generated::Description<T>::members().
Definition Describe.hpp:86
constexpr decltype(auto) get(Owner &object) const
Definition Describe.hpp:70
constexpr decltype(auto) get(const Owner &object) const
Definition Describe.hpp:71
One described data member: its name and its member pointer.
Definition Describe.hpp:38
The parameter names of a described function, which C++ cannot supply itself.
Definition Describe.hpp:52