pars 0.2.1.99
Loading...
Searching...
No Matches
klass.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
32#include "nngxx/msg.h"
33
34#include "pars/concept/kind.h"
35#include "pars/net/hash.h"
36
37#include <string_view>
38
39namespace pars::ev
40{
41
42template<typename class_t>
43struct uuid
44{
45 using class_type = class_t;
46
47 static constexpr std::size_t hash = hash_from_uuid(class_type::uuid);
48};
49
50template<typename event_t>
52{
53 using event_type = event_t;
54
56 static constexpr bool requires_network = true;
57
59 template<template<typename> typename kind_of>
60 requires kind_c<kind_of>
61 static constexpr executes exec_policy()
62 {
63 return executes::sync;
64 }
65};
66
67template<typename event_t>
68struct klass
69{
70 using event_type = event_t;
71};
72
73template<>
74struct klass<nngxx::msg> : base_klass<nngxx::msg>
75{
77
78 static constexpr std::string_view uuid =
79 "a7c09171-c503-4cb2-97e4-de8d3fe621b3";
80};
81
82template<event_c event_t>
83struct klass<std::shared_ptr<event_t>> : base_klass<event_t>
84{
85 using event_type = std::shared_ptr<event_t>;
86
87 using inner_event_type = event_t;
88
89 static constexpr std::string_view uuid = klass<inner_event_type>::uuid;
90
91 template<template<typename> typename kind_of>
92 requires kind_c<kind_of>
93 static constexpr executes exec_policy()
94 {
96 }
97
98 template<typename Archive>
99 static void serialize(event_type& ev, Archive& ar)
100 {
101 ev.reset(new inner_event_type{});
102
104 }
105};
106
107} // namespace pars::ev
Definition aio.h:35
clev::own< nng_msg * > msg
Definition msg.h:39
executes
Definition event.h:41
static constexpr executes exec_policy()
an event_t executes synchronously in every possibile kind_of<event_t>
Definition klass.h:61
static constexpr bool requires_network
by default, an event_t requires network
Definition klass.h:56
event_t event_type
Definition klass.h:53
static constexpr std::string_view uuid
Definition klass.h:78
static constexpr std::string_view uuid
Definition klass.h:89
static void serialize(event_type &ev, Archive &ar)
Definition klass.h:99
std::shared_ptr< event_t > event_type
Definition klass.h:85
static constexpr executes exec_policy()
Definition klass.h:93
event_t event_type
Definition klass.h:70
static constexpr std::size_t hash
Definition klass.h:47
class_t class_type
Definition klass.h:45