SObjectizer 5.8
Loading...
Searching...
No Matches
prefix.hpp
Go to the documentation of this file.
1/*
2 * SObjectizer-5
3 */
4
5/*!
6 * \file
7 * \since
8 * v.5.5.4
9 *
10 * \brief A type for storing prefix of data_source name.
11 */
12
13#pragma once
14
15#include <string>
16#include <string_view>
17#include <cstring>
18#include <ostream>
19
20namespace so_5
21{
22
23namespace stats
24{
25
26/*!
27 * \brief A type for storing prefix of data_source name.
28 *
29 * \since v.5.5.4
30 */
32 {
33 public :
34 //! Max length of prefix (not including 0-symbol at the end).
35 static constexpr const std::size_t max_length = 47;
36 //! Max size of buffer for prefix value (including 0-symbol at the end).
37 static constexpr const std::size_t max_buffer_size = max_length + 1;
38
39 //! Default constructor creates empty prefix.
40 constexpr prefix_t() noexcept
41 : m_value{ 0 }
42 {}
43
44// clang++ complaints about unsafe pointer arithmetics.
45// Attempt to use strncpy leads to warnings in VC++.
46#if defined(__clang__) && (__clang_major__ >= 16)
47#pragma clang diagnostic push
48#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
49#endif
50 //! Initializing constructor.
51 /*!
52 * Gets no more than max_length symbols.
53 */
54 constexpr prefix_t( const char * value ) noexcept
55 : m_value{}
56 {
57 char * last = m_value + max_length;
58 char * pos = m_value;
59 while( *value && pos != last )
60 {
61 *(pos++) = *(value++);
62 }
63 *pos = 0;
64 }
65#if defined(__clang__) && (__clang_major__ >= 16)
66#pragma clang diagnostic pop
67#endif
68
69 //! Initializing constructor.
70 /*!
71 * Gets no more than max_length symbols.
72 */
73 prefix_t( const std::string & value ) noexcept( noexcept(value.c_str()) )
74 : prefix_t( value.c_str() )
75 {}
76
77 //! Access to prefix value.
78 [[nodiscard]]
79 constexpr const char *
80 c_str() const noexcept
81 {
82 return m_value;
83 }
84
85 //! Access to prefix value as string_view.
86 /*!
87 * \since v.5.8.2
88 */
89 [[nodiscard]]
90 constexpr std::string_view
91 as_string_view() const noexcept( noexcept(std::string_view{std::declval<const char *>()}) )
92 {
93 return { m_value };
94 }
95
96 //! Is prefix empty?
97 [[nodiscard]]
98 constexpr bool
99 empty() const noexcept
100 {
101 return 0 == m_value[ 0 ];
102 }
103
104 //! Is equal?
105 [[nodiscard]]
106 bool
107 operator==( const prefix_t & o ) const noexcept
108 {
109 return 0 == strcmp( c_str(), o.c_str() );
110 }
111
112 //! Is not equal?
113 [[nodiscard]]
114 bool
115 operator!=( const prefix_t & o ) const noexcept
116 {
117 return 0 != strcmp( c_str(), o.c_str() );
118 }
119
120 //! Is less than?
121 [[nodiscard]]
122 bool
123 operator<( const prefix_t & o ) const noexcept
124 {
125 return 0 < strcmp( c_str(), o.c_str() );
126 }
127
128 private :
129 //! Actual value.
131 };
132
133/*!
134 * \brief Just a helper operator.
135 *
136 * \since v.5.5.4
137 */
138inline std::ostream &
139operator<<( std::ostream & to, const prefix_t & what )
140 {
141 return (to << what.c_str());
142 }
143
144/*!
145 * \brief A type for representing the suffix of data_source name.
146 *
147 * \note This is just a wrapper around `const char *`.
148 *
149 * \attention
150 * It's assumed that suffix_t holds a pointer to a string in static memory
151 * (it's a pointer to a string literal).
152 *
153 * \since v.5.5.4
154 */
156 {
157 public :
158 //! Initializing constructor.
159 constexpr suffix_t(
160 //! Value. It's expected to be a pointer to a null-terminated string.
161 const char * value ) noexcept
162 : m_value( value )
163 {}
164
165 //! Access to suffix value.
166 [[nodiscard]]
167 constexpr const char *
168 c_str() const noexcept
169 {
170 return m_value;
171 }
172
173 //! Access to prefix value as string_view.
174 /*!
175 * \since v.5.8.2
176 */
177 [[nodiscard]]
178 constexpr std::string_view
179 as_string_view() const noexcept( noexcept(std::string_view{std::declval<const char *>()}) )
180 {
181 return { m_value };
182 }
183
184 //! Compares suffixes by pointer values.
185 [[nodiscard]]
186 constexpr bool
187 operator==( const suffix_t & o ) const noexcept
188 {
189 return m_value == o.m_value;
190 }
191
192 //! Compares suffixes by pointer value.
193 [[nodiscard]]
194 constexpr bool
195 operator!=( const suffix_t & o ) const noexcept
196 {
197 return m_value != o.m_value;
198 }
199
200 //! Compares suffixes by pointer value.
201 [[nodiscard]]
202 constexpr bool
203 operator<( const suffix_t & o ) const noexcept
204 {
205 return m_value < o.m_value;
206 }
207
208 private :
209 //! Actual value.
210 const char * m_value;
211 };
212
213/*!
214 * \brief Just a helper operator.
215 *
216 * \since v.5.5.4
217 */
218inline std::ostream &
219operator<<( std::ostream & to, const suffix_t & what )
220 {
221 return (to << what.c_str());
222 }
223
224} /* namespace stats */
225
226} /* namespace so_5 */
A base class for agents.
Definition agent.hpp:673
void so_bind_to_dispatcher(event_queue_t &queue) noexcept
Binding agent to the dispatcher.
Definition agent.cpp:872
Alias for namespace with traits of event queue.
const queue_traits::queue_params_t & queue_params() const
Getter for queue parameters.
disp_params_t & tune_queue_params(L tunner)
Tuner for queue parameters.
queue_traits::queue_params_t m_queue_params
Queue parameters.
friend void swap(disp_params_t &a, disp_params_t &b) noexcept
disp_params_t & set_queue_params(queue_traits::queue_params_t p)
Setter for queue parameters.
disp_params_t()=default
Default constructor.
A handle for active_group dispatcher.
dispatcher_handle_t(impl::basic_dispatcher_iface_shptr_t dispatcher) noexcept
impl::basic_dispatcher_iface_shptr_t m_dispatcher
A reference to actual implementation of a dispatcher.
bool empty() const noexcept
Is this handle empty?
void reset() noexcept
Drop the content of handle.
bool operator!() const noexcept
Does this handle contain a reference to dispatcher?
operator bool() const noexcept
Is this handle empty?
disp_binder_shptr_t binder(nonempty_name_t group_name) const
Get a binder for that dispatcher.
const std::string m_group_name
Name of group for new agents.
void preallocate_resources(agent_t &) override
Allocate resources in dispatcher for new agent.
void unbind(agent_t &) noexcept override
Unbind agent from dispatcher.
void bind(agent_t &agent) noexcept override
Bind agent to dispatcher.
actual_dispatcher_iface_shptr_t m_disp
Dispatcher to be used.
void undo_preallocation(agent_t &) noexcept override
Undo resources allocation.
actual_binder_t(actual_dispatcher_iface_shptr_t disp, nonempty_name_t group_name) noexcept
An actual interface of active group dispatcher.
virtual so_5::event_queue_t * query_thread_for_group(const std::string &group_name) noexcept=0
Get the event_queue for the specified active group.
virtual void release_thread_for_group(const std::string &group_name) noexcept=0
Release the thread for the specified active group.
virtual void allocate_thread_for_group(const std::string &group_name)=0
Create a new thread for a group if it necessary.
The very basic interface of active_group dispatcher.
virtual disp_binder_shptr_t binder(nonempty_name_t group_name)=0
static dispatcher_handle_t make(actual_dispatcher_iface_shptr_t disp) noexcept
outliving_reference_t< dispatcher_template_t > m_dispatcher
Dispatcher to work with.
void distribute_value_for_work_thread(const so_5::mbox_t &mbox, const std::string &group_name, const thread_with_refcounter_t &wt)
disp_data_source_t(const std::string_view name_base, outliving_reference_t< dispatcher_template_t > disp)
void distribute(const so_5::mbox_t &mbox) override
Send appropriate notification about the current value.
void release_thread_for_group(const std::string &group_name) noexcept override
Release the thread for the specified active group.
void allocate_thread_for_group(const std::string &group_name) override
Create a new thread for a group if it necessary.
outliving_reference_t< environment_t > m_env
SObjectizer Environment to work in.
so_5::event_queue_t * query_thread_for_group(const std::string &group_name) noexcept override
Get the event_queue for the specified active group.
active_group_map_t m_groups
A map of dispatchers for active groups.
const disp_params_t m_params
Parameters for the dispatcher.
dispatcher_template_t(outliving_reference_t< environment_t > env, const std::string_view name_base, disp_params_t params)
work_thread_shptr_t search_and_try_remove_group_from_map(const std::string &group_name) noexcept
Helper function for searching and erasing agent's thread from map of active threads.
stats::auto_registered_source_holder_t< disp_data_source_t > m_data_source
Data source for run-time monitoring.
disp_binder_shptr_t binder(nonempty_name_t group_name) override
Container for storing parameters for MPSC queue.
const lock_factory_t & lock_factory() const
Getter for lock factory.
queue_params_t & operator=(queue_params_t &&o) noexcept
Move operator.
friend void swap(queue_params_t &a, queue_params_t &b) noexcept
so_5::stats::work_thread_activity_stats_t take_activity_stats()
Get the activity stats.
so_5::current_thread_id_t thread_id() const
Get ID of work thread.
friend void swap(work_thread_activity_tracking_flag_mixin_t &a, work_thread_activity_tracking_flag_mixin_t &b) noexcept
Mixin that holds optional work thread factory.
friend void swap(work_thread_factory_mixin_t &a, work_thread_factory_mixin_t &b) noexcept
An analog of unique_ptr for abstract_work_thread.
Interface for dispatcher binders.
SObjectizer Environment.
stats::repository_t & stats_repository()
Access to repository of data sources for run-time monitoring.
so_5::disp::abstract_work_thread_factory_shptr_t work_thread_factory() const noexcept
Access to the global work thread factory.
An interface of event queue for agent.
A class for the name which cannot be empty.
std::string giveout_value() noexcept(noexcept(std::string{ std::move(m_nonempty_name) }))
Get the value away from the object.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
T & get() const noexcept
outliving_reference_t(outliving_reference_t const &o) noexcept
A holder for data-souce that should be automatically registered and deregistered in registry.
A type for storing prefix of data_source name.
Definition prefix.hpp:32
bool operator<(const prefix_t &o) const noexcept
Is less than?
Definition prefix.hpp:123
constexpr prefix_t() noexcept
Default constructor creates empty prefix.
Definition prefix.hpp:40
constexpr bool empty() const noexcept
Is prefix empty?
Definition prefix.hpp:99
static constexpr const std::size_t max_buffer_size
Max size of buffer for prefix value (including 0-symbol at the end).
Definition prefix.hpp:37
constexpr std::string_view as_string_view() const noexcept(noexcept(std::string_view{std::declval< const char * >()}))
Access to prefix value as string_view.
Definition prefix.hpp:91
constexpr const char * c_str() const noexcept
Access to prefix value.
Definition prefix.hpp:80
constexpr prefix_t(const char *value) noexcept
Initializing constructor.
Definition prefix.hpp:54
bool operator!=(const prefix_t &o) const noexcept
Is not equal?
Definition prefix.hpp:115
static constexpr const std::size_t max_length
Max length of prefix (not including 0-symbol at the end).
Definition prefix.hpp:35
char m_value[max_buffer_size]
Actual value.
Definition prefix.hpp:130
prefix_t(const std::string &value) noexcept(noexcept(value.c_str()))
Initializing constructor.
Definition prefix.hpp:73
bool operator==(const prefix_t &o) const noexcept
Is equal?
Definition prefix.hpp:107
An interface of data source.
A type for representing the suffix of data_source name.
Definition prefix.hpp:156
constexpr bool operator<(const suffix_t &o) const noexcept
Compares suffixes by pointer value.
Definition prefix.hpp:203
constexpr bool operator==(const suffix_t &o) const noexcept
Compares suffixes by pointer values.
Definition prefix.hpp:187
constexpr const char * c_str() const noexcept
Access to suffix value.
Definition prefix.hpp:168
const char * m_value
Actual value.
Definition prefix.hpp:210
constexpr std::string_view as_string_view() const noexcept(noexcept(std::string_view{std::declval< const char * >()}))
Access to prefix value as string_view.
Definition prefix.hpp:179
constexpr suffix_t(const char *value) noexcept
Initializing constructor.
Definition prefix.hpp:159
constexpr bool operator!=(const suffix_t &o) const noexcept
Compares suffixes by pointer value.
Definition prefix.hpp:195
#define SO_5_FUNC
Definition declspec.hpp:48
Helpers for manipulation with standard C++ I/O streams.
Some reusable and low-level classes/functions which can be used in public header files.
void shutdown_and_wait(T &w)
Just a helper function for consequetive call to shutdown and wait.
void send_thread_activity_stats(const so_5::mbox_t &, const stats::prefix_t &, work_thread::work_thread_no_activity_tracking_t &)
void send_thread_activity_stats(const so_5::mbox_t &mbox, const stats::prefix_t &prefix, work_thread::work_thread_with_activity_tracking_t &wt)
Active groups dispatcher implemetation details.
Active groups dispatcher.
dispatcher_handle_t make_dispatcher(so_5::environment_t &env, const std::string_view data_sources_name_base)
Create an instance of active_group dispatcher.
dispatcher_handle_t make_dispatcher(so_5::environment_t &env)
Create an instance of active_group dispatcher.
SO_5_FUNC dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, disp_params_t params)
Create an instance of active_group dispatcher.
Various stuff related to MPSC event queue implementation and tuning.
Implemetation details of dispatcher's working thread.
Reusable components for dispatchers.
abstract_work_thread_factory_shptr_t actual_work_thread_factory_to_use(const work_thread_factory_mixin_t< Params > &params, const environment_t &env) noexcept
Helper to detect actual work thread factory to be used.
work_thread_holder_t acquire_work_thread(const work_thread_factory_mixin_t< Params > &params, environment_t &env)
Helper function for acquiring a new worker thread from an appropriate work thread factory.
so_5::stats::prefix_t make_disp_prefix(const std::string_view disp_type, const std::string_view data_sources_name_base, const void *disp_this_pointer)
Create basic prefix for dispatcher data source names.
so_5::stats::prefix_t make_disp_working_thread_prefix(const so_5::stats::prefix_t &disp_prefix, std::size_t thread_number)
Create prefix for dispatcher's working thread data source.
std::unique_ptr< Disp_Iface_Type > make_actual_dispatcher(outliving_reference_t< environment_t > env, const std::string_view name_base, Disp_Params_Type disp_params, Args &&...args)
Helper function for creation of dispatcher instance with respect to work thread activity tracking fla...
Event dispatchers.
Declarations of messages used by run-time monitoring and statistics.
Definition messages.hpp:36
Predefined suffixes of data-sources.
Definition std_names.hpp:55
SO_5_FUNC suffix_t agent_count()
Suffix for data source with count of agents bound to some entity.
Definition std_names.cpp:66
SO_5_FUNC suffix_t work_thread_queue_size()
Suffix for data source with count of demands in a working thread event queue.
Definition std_names.cpp:78
SO_5_FUNC suffix_t disp_active_group_count()
Suffix for data source with count of active groups in an active_group dispatcher.
Definition std_names.cpp:72
SO_5_FUNC suffix_t work_thread_activity()
Suffix for data source with work thread activity statistics.
Definition std_names.cpp:84
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
Definition agent.cpp:33
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
outliving_reference_t< T > outliving_mutable(T &r)
Make outliving_reference wrapper for mutable reference.
Helper for showing only part of long string.
length_limited_string(const std::string_view what, std::size_t limit)
Helper for showing pointer value.
A message with value of some quantity.
Definition messages.hpp:60
Information about one work thread activity.
Definition messages.hpp:108