"ScL Feature"/
ScL Feature 0.0.1
C++20 composable proxy wrapper with pluggable executor strategy
Loading...
Searching...
No Matches
property.h File Reference

Compile-time property reflection macro for wrapper types. More...

Go to the source code of this file.

Macros

#define SCL_REFLECT_PROPERTY(prop)
 Generates a wrapper data member that reflects field prop of the wrapped object through the executor.

Detailed Description

Compile-time property reflection macro for wrapper types.

Provides SCL_REFLECT_PROPERTY to generate a data-member proxy that forwards field access from the enclosing wrapper class to the held object through the executor, preserving cv-ref qualifiers exactly.

Requirements on the enclosing class
The same requirements as SCL_REFLECT_METHOD apply:
  1. Declare the executor data member. It must precede every SCL_REFLECT_PROPERTY: the generated member initializer reads the executor through executor_trait, so the executor subobject has to be constructed first (member initialization follows declaration order).
  2. Place SCL_REFLECT_TYPE(Type, Member) after the executor declaration.
  3. Specialize scl::feature::executor_trait for the wrapper type.
  4. Use SCL_REFLECT_PROPERTY inside the class body after SCL_REFLECT_TYPE.
Difference from SCL_REFLECT_METHOD
SCL_REFLECT_PROPERTY exposes a data field (wrapper.prop) rather than a method (wrapper.prop()). Read access uses implicit conversion via wrapper_cast(w.prop); write access uses wrapper_cast(w.prop).to<FieldType&>() for fundamental types, or operator= for class types that provide it.
ScLExec override
If the executor provides a static property_<name>(exec cv_ref) member whose first parameter matches a specific cv-ref qualification exactly (detected via a function-pointer cast, the same technique as has_execute_v), property access for that qualification calls the override directly, bypassing execute(). This is analogous to method_<name> overrides in SCL_REFLECT_METHOD.
Copy / move safety
The generated member stores a byte offset instead of a raw pointer, so memberwise copy and move work correctly without custom constructors.
Limitations
The offset is computed with reinterpret_cast (the container_of idiom), which is not a constant expression. Consequently a reflected property member cannot be used in a constant expression, and the enclosing wrapper is not constexpr-constructible while it carries SCL_REFLECT_PROPERTY members.
Example
struct PairWrapper;
template <>
struct scl::feature::executor_trait<PairWrapper> {
template <typename Self>
static constexpr decltype(auto) executor(Self && self)
{ return ::scl::forward_like<Self>(self.m_impl); }
};
struct PairWrapper {
::scl::feature::inplace::plain<std::pair<int,int>> m_impl;
SCL_REFLECT_TYPE(PairWrapper, m_impl);
};
PairWrapper w{std::pair{1, 2}};
wrapper_cast(w.first).to<int &>() = 42; // writes through executor
int x = wrapper_cast(w.first); // reads through executor → 42
#define SCL_REFLECT_TYPE(type, executor)
Declares the wrapper and executor types for use by SCL_REFLECT_METHOD.
Definition type.h:27
constexpr decltype(auto) wrapper_cast(Wrapper &&w)
Returns a lazy-locking cast proxy for a wrapper reference.
#define SCL_REFLECT_PROPERTY(prop)
Generates a wrapper data member that reflects field prop of the wrapped object through the executor.
Definition property.h:195
Trait that provides access to the executor inside a wrapper.
Definition executor.h:39
Parameters
propUnqualified data member name on the wrapped type.
See also
SCL_REFLECT_TYPE
SCL_REFLECT_METHOD
scl::feature::detail::property_execution

Macro Definition Documentation

◆ SCL_REFLECT_PROPERTY

#define SCL_REFLECT_PROPERTY ( prop)

Generates a wrapper data member that reflects field prop of the wrapped object through the executor.

Expands to a tag struct followed by one data member inside the enclosing class:

// 1. Tag struct for override detection (SCL_REFLECT_PROPERTY_EXEC_HELPERS):
struct property_prop_scl_tag { ... };
// 2. Data member (SCL_DECLTYPE_PROPERTY + initializer):
::scl::wrapper<FieldType,
property_execution<ExecutorType, Tag>::holder> prop{
&executor_trait<s_c_l_type>::executor(*static_cast<s_c_l_type*>(this)),
&OuterValueType::prop
};
Composable proxy wrapper that delegates to Value through executors.
Definition wrapper.h:72
ScLExec override
If the executor provides
static R property_##prop(ScLExec cv_ref exec);
then property access for that cv-ref qualification calls the override directly, bypassing execute(). Other qualifications fall through to the execute path. The override must return a type compatible with PropertyType (typically PropertyType&).

The inner wrapper's executor (property_execution<ExecutorType, Tag>::holder) stores a signed byte offset from its own address to the outer executor, so memberwise copy and move of the enclosing wrapper work correctly without custom constructors.

Parameters
propUnqualified data member name on the wrapped type.
See also
SCL_REFLECT_TYPE
SCL_REFLECT_PROPERTY_EXEC_HELPERS
scl::feature::detail::property_execution