SObjectizer-5 Extra
Loading...
Searching...
No Matches
just_envelope.hpp
Go to the documentation of this file.
1/*!
2 * \file
3 * \brief An implementation of just_envelope_t class.
4 *
5 * \since
6 * v.1.2.0
7 */
8
9#pragma once
10
11#include <so_5_extra/enveloped_msg/errors.hpp>
12
13#include <so_5/enveloped_msg.hpp>
14
15namespace so_5 {
16
17namespace extra {
18
19namespace enveloped_msg {
20
21//
22// just_envelope_t
23//
24/*!
25 * \brief A very simple implementation of envelope which do nothing except
26 * holding a payload.
27 *
28 * This class can be used for:
29 *
30 * * testing purposes. When you need an eveloped message but do not to create
31 * own envelope class;
32 * * as a base type for more complex envelopes.
33 *
34 * An example of usage of just_envelope_t as base class for your own
35 * evelope class:
36 * \code
37 * class my_envelope : public so_5::extra::enveloped_msg::just_envelope_t
38 * {
39 * using base_type = so_5::extra::enveloped_msg::just_envelope_t;
40 * public:
41 * // Inherit constructor from base class.
42 * using base_type::base_type;
43 *
44 * // Override access_hook and do some action after
45 * // processing of payload.
46 * void
47 * access_hook(
48 * access_context_t context,
49 * handler_invoker_t & invoker ) noexcept override
50 * {
51 * // Delegate payload extraction to the base type.
52 * base_type::access_hook( context, invoker );
53 *
54 * // Do our own logic.
55 * do_some_action();
56 * }
57 * };
58 * \endcode
59 *
60 * \attention
61 * This type of envelope inherits mutability from the payload. If the payload
62 * is mutable then the envelope is also mutable. If the payload immutable
63 * the the envelope is immutable too.
64 * Mutability of an envelope can't changed.
65 * Method so5_change_mutability() will throw on attempt to
66 * set different mutibility value.
67 *
68 * \note
69 * This class is not Copyable nor Moveable.
70 *
71 * \since
72 * v.1.2.0
73 */
75 {
76 //! Actual payload.
77 /*!
78 * This attribute is mutable because there can be a need to
79 * have non-const reference to message_ref in const-methods.
80 *
81 * \note
82 * It can be nullptr if payload is a signal.
83 */
85
86 protected :
87 //! Get access to content of envelope.
88 [[nodiscard]]
90 whole_payload() const noexcept
91 {
92 return { m_payload };
93 }
94
95 //! Get access to payload only.
96 [[nodiscard]]
98 payload() const noexcept { return m_payload; }
99
100 // Mutability of payload will be returned as mutability
101 // of the whole envelope.
103 so5_message_mutability() const noexcept override
104 {
105 return message_mutability( m_payload );
106 }
107
108 // Disables changing of mutability by throwing an exception.
109 void
111 message_mutability_t new_value ) override
112 {
113 if( new_value != so5_message_mutability() )
114 SO_5_THROW_EXCEPTION(
117 "just_envelope_t prohibit changing of message mutability" );
118 }
119
120 public :
121 //! Initializing constructor.
123 so_5::message_ref_t payload )
125 {}
126 ~just_envelope_t() noexcept override = default;
127
128 // Disable Copy and Move for that class.
129 just_envelope_t( const just_envelope_t & ) = delete;
131
132 // Implementation of inherited methods.
133 void
135 access_context_t /*context*/,
136 handler_invoker_t & invoker ) noexcept override
137 {
138 invoker.invoke( whole_payload() );
139 }
140 };
141
142} /* namespace enveloped_msg */
143
144} /* namespace extra */
145
146} /* namespace so_5 */
A very simple implementation of envelope which do nothing except holding a payload.
message_mutability_t so5_message_mutability() const noexcept override
message_ref_t & payload() const noexcept
Get access to payload only.
void so5_change_mutability(message_mutability_t new_value) override
just_envelope_t(so_5::message_ref_t payload)
Initializing constructor.
void access_hook(access_context_t, handler_invoker_t &invoker) noexcept override
~just_envelope_t() noexcept override=default
just_envelope_t(just_envelope_t &&)=delete
just_envelope_t(const just_envelope_t &)=delete
payload_info_t whole_payload() const noexcept
Get access to content of envelope.
const int rc_mutabilty_of_envelope_cannot_be_changed
Mutability of payload message inside just_envelope can't be changed.
Definition errors.hpp:30
Ranges for error codes of each submodules.
Definition details.hpp:13