A simple proxy that delegates all calls to underlying actual mbox.
Sometimes it is necessary to create an own mbox that does some specific task. For example, counts the number of message of some specific type. Something like:
class my_mbox final : public so_5::abstract_message_box_t
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
std::size_t counter_{};
...
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
...
}
};
But it is hard to create a full implementation of so_5::abstract_message_box_t from the ground up. An existing mbox can be used for doing actual work:
class my_mbox final : public so_5::abstract_message_box_t
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
const so_5::mbox_t mbox_;
std::size_t counter_{};
...
public:
my_mbox(so_5::mbox_t mbox) : mbox_{std::move(mbox)} {}
...
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
mbox_->do_deliver_message(
msg_type, message, overlimit_reaction_deep);
}
};
But there is a small problem with this approach: so_5::abstract_message_box_t has a rich interface with a lot of pure virtual methods. It is a boring task to reimplement all of them.
In such cases simple_t can be used to reduce amount of developer's work:
{
bool is_appropriate_message_type(
const std::type_index & msg_type ) const { ... }
std::size_t counter_{};
public:
my_mbox(so_5::mbox_t mbox) : base_type{std::move(mbox)} {}
const std::type_index & msg_type,
const so_5::message_ref_t & message,
unsigned int overlimit_reaction_deep ) override {
if(is_appropriate_message_type(msg_type))
++counter_;
base_type::do_deliver_message(
msg_type, message, overlimit_reaction_deep);
}
}
And that's all.
- Since
- v.5.5.23
Definition at line 128 of file proxy.hpp.