|
SObjectizer
5.7
|
A class for holding an instance of a message. More...
#include <message_holder.hpp>
Public Types | |
| using | payload_type = typename base_type::payload_type |
| using | envelope_type = typename base_type::envelope_type |
Public Member Functions | |
| template<typename... Args> | |
| message_holder_t (std::piecewise_construct_t, Args &&...args) | |
Static Public Member Functions | |
| template<typename... Args> | |
| static message_holder_t | make (Args &&...args) |
| Create a new instance of message_holder with a new message inside. More... | |
Private Types | |
| using | base_type = details::message_holder_details::accessor_selector_t< details::message_mutability_traits< Msg >::mutability, details::message_holder_details::impl_selector_t< Msg, Ownership > > |
Static Private Member Functions | |
| template<typename... Args> | |
| static intrusive_ptr_t< envelope_type > | make_msg_instance (Args &&...args) |
| Create a new instance of message. More... | |
Friends | |
| void | swap (message_holder_t &a, message_holder_t &b) noexcept |
A class for holding an instance of a message.
This class is intended for simplification of holding message instances for some time and resending them later. For example:
This class is also intended to be used with preallocated messages:
The main benefit of that class is the ability to correctly handle messages of arbitrary user types (e.g. messages not derived from so_5::message_t class) and mutability flags. For example, the following cases are correctly handled by message_holder_t:
Class message_holder_t provides the following methods:
There are also some more methods which are depend on mutability of message and the type of ownership. They are described below.
If a message_holder holds an immutable message then there are the following getter methods:
But if message_holder holds a mutable message those getters are still here but they have non-const return type:
A message_holder works like a smart pointer. But what kind of smart pointer?
It depends on Ownership template parameters.
But default Ownership is so_5::message_ownership_t::autodetected. In this case the behavior of a message_holder depends of the mutability of message. If message is immutable then message_holders is like std::shared_ptr: several message_holders can hold pointers to the same message instances.
If message is mutable then message_holder is like std::unique_ptr: only one message_holder can hold a pointer to a message instance.
For example:
The value of Ownership parameter can be specified manually. In that case we can have an unique-holder for an immutable message:
There can also be a shared-holder for a mutable message:
But this approach should be taken with an additional care because it allows to make several sends of the same mutable message instances at the same time.
If a message_holder works as std::shared_ptr then there is the following methods:
If a message_holder works as std::unique_ptr then copy operator/constructors are disabled and make_reference() leaves the message_holder object empty:
There are several ways of creation of a message to be stored inside a message_holder object.
The recommended way is to use the constructor of message_holder with std::piecewise_construct_t argument. This constructor automatically creates an underlying message instance:
Sometimes a static method make() can be used for similar purpose:
But sometimes an instance of message is present as raw pointer, std::unique_ptr or so_5::intrusive_ptr_t objects. In that case the constructor that accepts intrusive_ptr_t can be used:
|
private |
| using so_5::message_holder_t< Msg, Ownership >::envelope_type = typename base_type::envelope_type |
| using so_5::message_holder_t< Msg, Ownership >::payload_type = typename base_type::payload_type |
|
inline |
Special constructor for constructing message_holder with a new message instance inside.
Usage example:
|
inlinestatic |
Create a new instance of message_holder with a new message inside.
Usage example:
|
inlinestaticprivate |
Create a new instance of message.
|
friend |
1.8.14