-
Notifications
You must be signed in to change notification settings - Fork 0
API muesli projector_codec
Defined in header <muesli/projector_codec>
template<Owner, Projector>
struct projector_codec : fluent::optionable<projector_codec<Owner, FieldCodec, Projector>>,
fluent::constrainable<projector_codec<Owner, FieldCodec, Projector>>,
fluent::transformable<projector_codec<Owner, FieldCodec, Projector>>,
fluent::constructable<projector_codec<Owner, FieldCodec, Projector>>Codec for projecting values from an owner type via custom lambda.
The projector_codec allows encoding a derived/projected value from an owner object using a custom projection function, enabling flexible value extraction patterns.
| Parameter | Description |
|---|---|
Owner |
The type containing the value to project |
FieldCodec |
The codec for the projected field type |
Projector |
Function taking const Owner& and returning the projected value |
owner_type
using owner_type = OwnerThe owner type containing the value
projector_type
using projector_type = ProjectorThe projector function type
value_type
using value_type = std::invoke_result_t<Projector, const Owner&>Value type is the result of invoking the projector
next_codec_type
using next_codec_type = std::decay_t<decltype(std::declval<FieldCodec>().next_codec())>Next codec in the encoding chain
encoded_type
using encoded_type = typename next_codec_type::value_typeEncoded type from the next codec
Constructs a projector_codec with field codec and projector function
constexpr projector_codec(const FieldCodec& fc, Projector proj) noexcept : field_codec(fc), projector(std::move(proj))struct Rectangle { int width, height; };
auto area_codec = projector_codec<Rectangle>(
int_codec,
[](const Rectangle& r) { return r.width * r.height; }
);using owner_type = Owner; /** @brief The projector function type */ using projector_type = Projector; /** @brief Value type is the result of invoking the projector */ using value_type = std::invoke_result_t<Projector, const Owner&>; /** @brief Next codec in the encoding chain */ using next_codec_type = std::decay_t<decltype(std::declval<FieldCodec>().next_codec())>; /** @brief Encoded type from the next codec */ using encoded_type = typename next_codec_type::value_type; /** @brief Codec for encoding/decoding the projected field */ FieldCodec field_codec; /** @brief Function to project values from owner objects */ Projector projector; /** @brief Constructs a projector_codec with field codec and projector function */ constexpr projector_codec(const FieldCodec& fc, Projector proj) noexcept : field_codec(fc), projector(std::move(proj))The owner type containing the value
constexpr next_codec_type next_codec() const noexceptReturns the next codec in the encoding chain
constexpr encoded_type encode(const value_type& value) const noexceptEncodes a projected value
constexpr value_type decode(const auto& value) const noexceptDecodes to the projected value type
constexpr value_type project(const owner_type& obj) const noexceptProjects a value from an owner object using the projector function
template<typename Owner, Codec ElementCodec, typename Projector> constexpr auto projector_of(const ElementCodec& elem, Projector projector)Helper function to create a projector_codec
| Parameter | Description |
|---|---|
Owner |
The type containing the value to project |
-
elem— The codec for the projected value -
projector— Function to extract the value from the owner
Returns: A projector_codec wrapping the element codec