pars
0.2.1.99
Loading...
Searching...
No Matches
lib
include
pars
concept
event.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2025 Giuseppe Roberti.
3
All rights reserved.
4
5
Redistribution and use in source and binary forms, with or without modification,
6
are permitted provided that the following conditions are met:
7
8
1. Redistributions of source code must retain the above copyright notice, this
9
list of conditions and the following disclaimer.
10
11
2. Redistributions in binary form must reproduce the above copyright notice,
12
this list of conditions and the following disclaimer in the documentation and/or
13
other materials provided with the distribution.
14
15
3. Neither the name of the copyright holder nor the names of its contributors
16
may be used to endorse or promote products derived from this software without
17
specific prior written permission.
18
19
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
ANY 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
28
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
30
#pragma once
31
32
#include "
pars/ev/kind_decl.h
"
33
34
#include <concepts>
35
#include <string_view>
36
37
namespace
pars::ev
38
{
39
40
enum class
executes
41
{
42
sync
,
43
async
44
};
45
46
template
<
typename
>
47
struct
klass;
48
49
// event_t is an event if klass<event_t> meets these requirements
50
template
<
typename
event_t>
51
concept
event_c
=
requires
{
52
requires
std::default_initializable<klass<event_t>>;
53
{
klass<event_t>::uuid
} -> std::same_as<const std::string_view&>;
54
{
klass<event_t>::requires_network
} -> std::same_as<const bool&>;
55
{
klass<event_t>::template
exec_policy<sent>() } -> std::same_as<executes>;
56
{
57
klass<event_t>::template
exec_policy<received>()
58
} -> std::same_as<executes>;
59
{
klass<event_t>::template
exec_policy<fired>() } -> std::same_as<executes>;
60
};
61
62
// an internal event event_t does not requires network
63
template
<
typename
event_t>
64
concept
internal_event_c
=
65
event_c<event_t>
&& !
klass<event_t>::requires_network
;
66
67
// a network event event_t requires network
68
template
<
typename
event_t>
69
concept
network_event_c
=
event_c<event_t>
&&
klass<event_t>::requires_network
;
70
71
// a synchronous event event_t requires sync exec_policy for kind_of
72
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
73
concept
sync_event_c
=
74
event_c<event_t>
&&
75
klass<event_t>::template
exec_policy<kind_of>() ==
executes::sync
;
76
77
// a synchronous internal event event_t
78
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
79
concept
sync_internal_event_c
=
80
internal_event_c<event_t>
&&
sync_event_c<event_t, kind_of>
;
81
82
// an synchronous network event event_t
83
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
84
concept
sync_network_event_c
=
85
network_event_c<event_t>
&&
sync_event_c<event_t, kind_of>
;
86
87
// an asynchronous event event_t requires async exec_policy for kind_of
88
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
89
concept
async_event_c
=
90
event_c<event_t>
&&
91
klass<event_t>::template
exec_policy<kind_of>() ==
executes::async
;
92
93
// an asynchronous internal event event_t for kind_of
94
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
95
concept
async_internal_event_c
=
96
async_event_c<event_t, kind_of>
&&
internal_event_c<event_t>
;
97
98
// an asynchronous network event event_t for kind_of
99
template
<
typename
event_t,
template
<
typename
>
typename
kind_of>
100
concept
async_network_event_c
=
101
async_event_c<event_t, kind_of>
&&
network_event_c<event_t>
;
102
103
}
// namespace pars::ev
pars::ev::async_event_c
Definition
event.h:89
pars::ev::async_internal_event_c
Definition
event.h:95
pars::ev::async_network_event_c
Definition
event.h:100
pars::ev::event_c
Definition
event.h:51
pars::ev::internal_event_c
Definition
event.h:64
pars::ev::network_event_c
Definition
event.h:69
pars::ev::sync_event_c
Definition
event.h:73
pars::ev::sync_internal_event_c
Definition
event.h:79
pars::ev::sync_network_event_c
Definition
event.h:84
kind_decl.h
pars::ev
Definition
event.h:38
pars::ev::executes
executes
Definition
event.h:41
pars::ev::executes::async
@ async
Definition
event.h:43
pars::ev::executes::sync
@ sync
Definition
event.h:42
pars::ev::klass
Definition
klass.h:69
Generated by
1.13.2