SObjectizer  5.5
Public Member Functions | Private Types | List of all members
so_5::mhood_t< M > Class Template Reference

A message wrapped to be used as type of argument for event handlers. More...

#include <mhood.hpp>

Inheritance diagram for so_5::mhood_t< M >:
so_5::details::mhood_base_t< M, T, Mut >

Public Member Functions

 mhood_t (message_ref_t &mf)
 

Private Types

using base_type_t = details::actual_mhood_base_type< M >
 

Detailed Description

template<typename M>
class so_5::mhood_t< M >

A message wrapped to be used as type of argument for event handlers.

Since
v.5.5.14
Template Parameters
Mtype of message or signal.
Note
This class provides different sets of methods in dependency of type M. If M is a type derived from so_5::message_t, then there will be the following methods for immutable message M:
const M * get() const;
const M * operator->() const;
const M & operator*() const;
so_5::intrusive_ptr_t< M > make_reference() const;
so_5::message_holder_t< M, Ownership > make_holder<Ownership>() const;
If M is a type derived from so_5::signal_t, then there will no be methods at all. It is because there is no actual message object for a signal. If M is user-type message then there will be the following methods for immutable message M:
const M * get() const;
const M * operator->() const;
const M & operator*() const;
so_5::message_holder_t< M, Ownership > make_holder<Ownership>() const;
For mutable message M there will be the following methods is M is derived from so_5::message_t:
M * get();
M * operator->();
M & operator*();
so_5::intrusive_ptr_t< M > make_reference();
so_5::message_holder_t< M, Ownership > make_holder<Ownership>();
If mutable message M is not derived from so_5::message_t then there will be the following methods:
M * get();
M * operator->();
M & operator*();
so_5::message_holder_t< M, Ownership > make_holder<Ownership>();
Method make_holder() uses so_5::message_ownership_t::autodetected by default.
Attention
Methods make_reference() for mhood_t<mutable_msg<M>> will leave mhood object in nullptr state. It means that mhood must not be used after calling make_reference().
Methods make_holder() for mhood_t<mutable_msg<M>> will leave the mhood object empty always. Regardless of Ownership parameter. Methods make_holder() for mhood_t<M> and mhood_t<immutable_msg<M>> will leave value for mhood object regardless of Ownership parameter. For example:
class demo : public agent_t {
void on_immutable_msg(mhood_t<some_msg> cmd) {
auto unique_holder = cmd.make_holder<so_5::message_ownership_t::unique>();
auto v = cmd->some_value(); // cmd still has its value.
...
}
...
void on_mutable_msg(mhood_t< mutable_msg<another_msg> > cmd) {
auto shared_holder = cmd.make_holder<so_5::message_ownership_t::shared>();
// Now cmd is empty!
auto v = cmd->some_value(); // THIS IS UB!
}
};
Note
Class mhood_t can be used for redirection of messages of user types. For example (since v.5.5.19):
class redirector : public so_5::agent_t
{
...
void some_event( mhood_t< std::string > evt ) {
// Redirection of message to the different mbox.
so_5::send(m_another_mbox, evt);
}
};
If mhood_t<mutable_msg<M>> is used then a redirection must be done this way:
class redirector : public so_5::agent_t
{
...
void some_event( mhood_t< mutable_msg<std::string> > evt ) {
// Redirection of message to the different mbox.
so_5::send(m_another_mbox, std::move(evt));
// NOTE: evt is nullptr at this point. It must not be used anymore.
}
};
Examples:
so_5/delivery_filters/main.cpp, so_5/make_pipeline/main.cpp, so_5/mchain_handler_formats/main.cpp, so_5/news_board/main.cpp, and so_5/wrapped_env_demo_3/main.cpp.

Member Typedef Documentation

◆ base_type_t

template<typename M>
using so_5::mhood_t< M >::base_type_t = details::actual_mhood_base_type<M>
private

Constructor & Destructor Documentation

◆ mhood_t()

template<typename M>
so_5::mhood_t< M >::mhood_t ( message_ref_t mf)
inline

The documentation for this class was generated from the following file: