SObjectizer 5.8
Loading...
Searching...
No Matches
so_5::msinks Namespace Reference

Namespaces

namespace  transform_then_redirect_impl
 

Functions

template<typename Transformer_Lambda >
msink_t transform_then_redirect (so_5::environment_t &env, Transformer_Lambda &&transformer)
 Factory function that creates an instance of transform_then_redirect msink.
 
template<typename Expected_Msg , typename Transformer_Lambda >
std::enable_if_t< !is_signal< Expected_Msg >::value, msink_ttransform_then_redirect (so_5::environment_t &env, Transformer_Lambda &&transformer)
 Factory function that creates an instance of transform_then_redirect msink.
 
template<typename Signal , typename Transformer_Lambda >
std::enable_if_t< is_signal< Signal >::value, msink_ttransform_then_redirect (so_5::environment_t &env, Transformer_Lambda &&transformer)
 Factory function that creates an instance of transform_then_redirect msink.
 

Function Documentation

◆ transform_then_redirect() [1/3]

template<typename Transformer_Lambda >
msink_t so_5::msinks::transform_then_redirect ( so_5::environment_t & env,
Transformer_Lambda && transformer )
nodiscard

Factory function that creates an instance of transform_then_redirect msink.

Attention
It's much simpler to use so_5::bind_transformer<Binding, Transformer>() function that calls this factory under the hood.

Type of source message is automatically deduced from the type of transformer argument.

Usage example:

struct part { ... };
struct compound {
part m_first;
part m_second;
};
...
so_5::mbox_t src_mbox = ...;
so_5::mbox_t dest_mbox = ...;
binding.bind<compound>(src_mbox,
src_mbox->environment(),
[dest_mbox](const compound & msg) {
return so_5::make_transformed<part>(
dest_mbox, // Destination for the transformed message.
msg.m_first // Initializer for the new `part` instance.
);
}));
Helper class for managing single sink bindings.
void bind(const mbox_t &source, const msink_t &sink_owner)
msink_t transform_then_redirect(so_5::environment_t &env, Transformer_Lambda &&transformer)
Factory function that creates an instance of transform_then_redirect msink.

The transformer is expected to return a so_5::transformed_message_t or std::optional<so_5::transformed_message_t>:

binding.bind(src_mbox,
src_mbox->environment(),
[dest_mbox](const compound & msg)
{
if(should_message_be_transformed(msg)) {
return {
so_5::make_transformed<part>(
dest_mbox, // Destination for the transformed message.
msg.m_first // Initializer for the new `part` instance.
) };
}
else
return std::nullopt; // No transformation.
}));
A result of message transformation.
Note
Because the type of the source message is deduced from transformer argument this factory function can't be used for transforming mutable messages and signals.
Attention
The transformer can't have an argument in the form of const auto &:
// Compilation error is expected here because the type of
// the transformer argument can't be deduced.
so_5::msinks::transform_then_redirect(env, [](const auto & msg) {...});
Template Parameters
Transformer_Lambdatype of transformer functor (a lambda or free function).
Since
v.5.8.1
Parameters
envSObjectizer Environment for that a new msink will be created.
transformerTransformer that produced so_5::transformed_message_t instance or std::optional<so_5::transformed_message_t> instance.

Definition at line 547 of file transform_then_redirect.hpp.

◆ transform_then_redirect() [2/3]

template<typename Expected_Msg , typename Transformer_Lambda >
std::enable_if_t< !is_signal< Expected_Msg >::value, msink_t > so_5::msinks::transform_then_redirect ( so_5::environment_t & env,
Transformer_Lambda && transformer )
nodiscard

Factory function that creates an instance of transform_then_redirect msink.

Attention
It's much simpler to use so_5::bind_transformer<Expected_Msg, Binding, Transformer>() function that calls this factory under the hood.

Type of source message is specified explicitly and because of that this factory function can be used for mutable messages too.

Usage example:

struct part { ... };
struct compound {
part m_first;
part m_second;
};
...
so_5::mbox_t src_mbox = ...;
so_5::mbox_t dest_mbox = ...;
binding.bind< so_5::mutable_msg<compound> >(src_mbox,
src_mbox->environment(),
[dest_mbox](compound & msg) { // or [dest_mbox](auto & msg)
dest_mbox, // Destination for the transformed message.
std::move(msg.m_first) // Initializer for the new `part` instance.
);
}));
transformed_message_t< Msg > make_transformed(mbox_t mbox, Args &&... args)
Helper function for creation of an instance of transformed_message_t.
A special marker for mutable message.
Definition message.hpp:383

The transformer is expected to return a so_5::transformed_message_t or std::optional<so_5::transformed_message_t>:

binding.bind< so_5::mutable_msg<compound> >(src_mbox,
src_mbox->environment(),
[dest_mbox](compound & msg)
{
if(should_message_be_transformed(msg)) {
return {
dest_mbox, // Destination for the transformed message.
std::move(msg.m_first) // Initializer for the new `part` instance.
) };
}
else
return std::nullopt; // No transformation.
}));
Attention
This factory function can't be used for signals.
Template Parameters
Expected_Msgtype of the source message or signal. When Msg is the source message type, then Msg, so_5::immutable_msg<Msg> or so_5::mutable_msg<Msg> can be used.
Transformer_Lambdatype of transformer functor (a lambda or free function).
Since
v.5.8.1
Parameters
envSObjectizer Environment for that a new msink will be created.
transformerTransformer that produced so_5::transformed_message_t instance or std::optional<so_5::transformed_message_t> instance.

Definition at line 642 of file transform_then_redirect.hpp.

◆ transform_then_redirect() [3/3]

template<typename Signal , typename Transformer_Lambda >
std::enable_if_t< is_signal< Signal >::value, msink_t > so_5::msinks::transform_then_redirect ( so_5::environment_t & env,
Transformer_Lambda && transformer )
nodiscard

Factory function that creates an instance of transform_then_redirect msink.

Attention
It's much simpler to use so_5::bind_transformer<Expected_Msg, Binding, Transformer>() function that calls this factory under the hood.
This overload of transform_then_redirect factory function can only be used with signals.

Usage example:

struct first_signal final : public so_5::signal_t {};
struct second_signal final : public so_5::signal_t {};
...
so_5::mbox_t src_mbox = ...;
so_5::mbox_t dest_mbox = ...;
binding.bind< first_signal >(src_mbox,
src_mbox->environment(),
[dest_mbox]() {
return so_5::make_transformed<second_signal>(
dest_mbox // Destination for the transformed message.
);
}));
A base class for agent signals.
Definition message.hpp:275

The transformer is expected to return a so_5::transformed_message_t or std::optional<so_5::transformed_message_t>.

Template Parameters
Expected_Msgtype of the source signal. When Expected_Msg is the source signal type then Expected_Msg or so_5::immutable_msg<Expected_Msg> is allowed.
Transformer_Lambdatype of transformer functor (a lambda or free function).
Since
v.5.8.1
Parameters
envSObjectizer Environment for that a new msink will be created.
transformerTransformer that produced so_5::transformed_message_t instance or std::optional<so_5::transformed_message_t> instance.

Definition at line 713 of file transform_then_redirect.hpp.