SObjectizer-5 Extra
Loading...
Searching...
No Matches
fixed_size.hpp
Go to the documentation of this file.
1/*!
2 * \file
3 * \brief Implementation of fixed-size mchain.
4 *
5 * \since
6 * v.1.4.0
7 */
8
9#pragma once
10
11#include <so_5/impl/mchain_details.hpp>
12#include <so_5/impl/make_mchain.hpp>
13#include <so_5/impl/internal_env_iface.hpp>
14
15#include <array>
16
17namespace so_5
18{
19
20namespace extra
21{
22
23namespace mchains
24{
25
26namespace fixed_size
27{
28
29namespace details
30{
31
32//
33// demand_queue_t
34//
35/*!
36 * \brief Implementation of demands queue for fixed-size message chain with
37 * "static" storage.
38 *
39 * \since
40 * v.1.4.0
41 */
42template< std::size_t Size >
44 {
45 public :
46 // NOTE: constructor of this format is necessary
47 // because the standard implementation of mchain from SO-5
48 // requires it.
50
51 //! Is queue full?
52 [[nodiscard]] bool
53 is_full() const { return Size == m_size; }
54
55 //! Is queue empty?
56 [[nodiscard]] bool
57 is_empty() const { return 0u == m_size; }
58
59 //! Access to front item of the queue.
62 {
64 return m_storage[ m_head ];
65 }
66
67 //! Remove the front item from queue.
68 void
76
77 //! Add a new item to the end of the queue.
78 void
79 push_back( so_5::mchain_props::demand_t && demand )
80 {
82 auto index = (m_head + m_size) % Size;
84 ++m_size;
85 }
86
87 //! Size of the queue.
88 std::size_t
89 size() const { return m_size; }
90
91 private :
92 //! Queue's storage.
94
95 //! Index of the queue head.
97 //! The current size of the queue.
99 };
100
101} /* namespace details */
102
103//
104// create_mchain
105//
106/*!
107 * \brief Helper function for creation of fixed-size mchain.
108 *
109 * Creates a mchain without waiting on attempt to push a new message
110 * into full mchain.
111 *
112 * Usage example:
113 * \code
114 so_5::wrapped_env_t sobj;
115
116 auto reply_ch = so_5::extra::mchains::fixed_size::create_mchain<1>(
117 sobj.environment(),
118 so_5::mchain_props::overflow_reaction_t::drop_newest);
119 * \endcode
120 *
121 * \brief
122 * v.1.4.0
123 */
124template< std::size_t Size >
125[[nodiscard]] mchain_t
143
144//
145// create_mchain
146//
147/*!
148 * \brief Helper function for creation of fixed-size mchain.
149 *
150 * Creates a mchain with waiting on attempt to push a new message
151 * into full mchain.
152 *
153 * Usage example:
154 * \code
155 so_5::wrapped_env_t sobj;
156
157 auto reply_ch = so_5::extra::mchains::fixed_size::create_mchain<5>(
158 sobj.environment(),
159 std::chrono::milliseconds{250},
160 so_5::mchain_props::overflow_reaction_t::remove_oldest);
161 * \endcode
162 *
163 * \brief
164 * v.1.4.0
165 */
166template< std::size_t Size >
167[[nodiscard]] mchain_t
187
188//
189// create_mchain
190//
191/*!
192 * \brief Helper function for creation of fixed-size mchain.
193 *
194 * Usage example:
195 * \code
196 so_5::wrapped_env_t sobj;
197
198 auto params = so_5::make_limited_with_waiting_mchain_params(
199 1, // Will be ignored.
200 so_5::mchain_props::memory_usage_t::preallocated, // Will be ignored.
201 so_5::mchain_props::overflow_reaction_t::throw_exception,
202 std::chrono::seconds{3});
203 params.disable_msg_tracing();
204 params.not_empty_notificator([]{...});
205
206 auto reply_ch = so_5::extra::mchains::fixed_size::create_mchain<20>(
207 sobj.environment(),
208 params);
209 * \endcode
210 *
211 * \attention
212 * Value of params.capacity() will be ignored.
213 *
214 * \brief
215 * v.1.4.0
216 */
217template< std::size_t Size >
218[[nodiscard]] mchain_t
221 const so_5::mchain_params_t & params )
222 {
224
227 // NOTE: some of params's value won't be used.
228 params,
229 env,
231 }
232
233} /* namespace fixed_size */
234
235} /* namespace mchains */
236
237} /* namespace extra */
238
239} /* namespace so_5 */
Implementation of demands queue for fixed-size message chain with "static" storage.
std::size_t m_size
The current size of the queue.
std::array< so_5::mchain_props::demand_t, Size > m_storage
Queue's storage.
void pop_front()
Remove the front item from queue.
void push_back(so_5::mchain_props::demand_t &&demand)
Add a new item to the end of the queue.
so_5::mchain_props::demand_t & front()
Access to front item of the queue.
mchain_t create_mchain(environment_t &env, so_5::mchain_props::duration_t wait_timeout, so_5::mchain_props::overflow_reaction_t overflow_reaction)
Helper function for creation of fixed-size mchain.
mchain_t create_mchain(environment_t &env, so_5::mchain_props::overflow_reaction_t overflow_reaction)
Helper function for creation of fixed-size mchain.
mchain_t create_mchain(environment_t &env, const so_5::mchain_params_t &params)
Helper function for creation of fixed-size mchain.
Ranges for error codes of each submodules.
Definition details.hpp:13