pars 0.2.1
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/*
2Copyright (c) 2025 Giuseppe Roberti.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30#pragma once
31
32constexpr auto enable_compute_fib_async = true;
33
34#include <pars/pars.h>
35
36#include <format>
37#include <string>
38
39using namespace pars;
40using namespace pars::ev;
41
43{
44
55
63
71
73{
75
77 : state{s}
78 {
79 }
80
81 pipe_resource(const pipe_resource&) = delete;
82
84
85 void save_tool(net::tool_view t) { tool_m.emplace(t); }
86
87 const net::tool_view& load_tool() const { return *tool_m; }
88
89private:
90 std::optional<net::tool_view> tool_m;
91};
92
93} // namespace pars_example::resource
94
95template<>
97 : std::formatter<std::string>
98{
99 auto format(const ::pars_example::resource::client_state& s,
100 format_context& ctx) const -> decltype(ctx.out())
101 {
102 using client_state = pars_example::resource::client_state;
103
104 switch (s)
105 {
106 case client_state::creating:
107 return format_to(ctx.out(), "creating");
108 break;
109
110 case client_state::initializing:
111 return format_to(ctx.out(), "initializing");
112 break;
113
114 case client_state::started:
115 return format_to(ctx.out(), "started");
116 break;
117
118 case client_state::sending_work:
119 return format_to(ctx.out(), "sending work");
120 break;
121
122 case client_state::waiting_work_done:
123 return format_to(ctx.out(), "waiting work done");
124 break;
125
126 case client_state::terminating:
127 return format_to(ctx.out(), "terminating");
128 break;
129
130 case client_state::terminated:
131 return format_to(ctx.out(), "terminated");
132 break;
133
134 default:
135 return format_to(ctx.out(), "<client_state-{}>", static_cast<int>(s));
136 break;
137 }
138 }
139};
140
141template<>
143 : std::formatter<std::string>
144{
145 auto format(const ::pars_example::resource::server_state& s,
146 format_context& ctx) const -> decltype(ctx.out())
147 {
148 using server_state = pars_example::resource::server_state;
149
150 switch (s)
151 {
152 case server_state::creating:
153 return format_to(ctx.out(), "creating");
154 break;
155
156 case server_state::initializing:
157 return format_to(ctx.out(), "initializing");
158 break;
159
160 case server_state::running:
161 return format_to(ctx.out(), "running");
162 break;
163
164 case server_state::terminating:
165 return format_to(ctx.out(), "terminating");
166 break;
167
168 default:
169 return format_to(ctx.out(), "<server_state-{}>", static_cast<int>(s));
170 break;
171 }
172 }
173};
174
175template<>
177 : std::formatter<std::string>
178{
179 auto format(const ::pars_example::resource::pipe_state& s,
180 format_context& ctx) const -> decltype(ctx.out())
181 {
182 using pipe_state = pars_example::resource::pipe_state;
183
184 switch (s)
185 {
186 case pipe_state::waiting_work:
187 return format_to(ctx.out(), "waiting work");
188 break;
189
190 case pipe_state::working:
191 return format_to(ctx.out(), "working");
192 break;
193
194 case pipe_state::done:
195 return format_to(ctx.out(), "done");
196 break;
197
198 case pipe_state::failing:
199 return format_to(ctx.out(), "failing");
200 break;
201
202 default:
203 return format_to(ctx.out(), "<pipe_state-{}>", static_cast<int>(s));
204 break;
205 }
206 }
207};
Represents an nng_socket or nng_ctx view.
Definition tool_view.h:48
constexpr auto enable_compute_fib_async
Definition common.h:32
pipe_resource(const pipe_resource &)=delete
void save_tool(net::tool_view t)
Definition common.h:85
app::state_machine< pipe_state > state
Definition common.h:74
pipe_resource(pipe_resource &&)=delete
const net::tool_view & load_tool() const
Definition common.h:87
auto format(const ::pars_example::resource::client_state &s, format_context &ctx) const -> decltype(ctx.out())
Definition common.h:99
auto format(const ::pars_example::resource::pipe_state &s, format_context &ctx) const -> decltype(ctx.out())
Definition common.h:179
auto format(const ::pars_example::resource::server_state &s, format_context &ctx) const -> decltype(ctx.out())
Definition common.h:145