pars 0.2.1.99
Loading...
Searching...
No Matches
value.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 "clev/own.h"
33#include "clev/value.h"
34#include "nngxx/concept.h"
35#include "nngxx/opt.h"
36#include "nngxx/opt_getter.h"
37#include "nngxx/opt_setter.h"
38
39#include <type_traits>
40
41namespace nngxx
42{
43
44template<nng_c nng_t>
45struct value : clev::value<nng_t>
46{
48
49 using parent::parent;
50
52
53 [[nodiscard]] inline static bool is_valid(nng_type v) noexcept
54 {
55 if constexpr (std::is_pointer_v<nng_type>)
56 return v != nullptr;
57 else
58 return v.id != 0;
59 }
60
62
63 [[nodiscard]] inline clev::expected<void>
64 set_recv_timeout(nng_duration d) noexcept
65 {
66 return set_option<opt::recvtimeo>(d);
67 }
68
69 [[nodiscard]] inline clev::expected<void>
70 set_send_timeout(nng_duration d) noexcept
71 {
72 return set_option<opt::sendtimeo>(d);
73 }
74
75 [[nodiscard]] inline clev::expected<void>
76 set_req_resend_time(nng_duration d) noexcept
77 {
78 return set_option<opt::req_resend_time>(d);
79 }
80
81 [[nodiscard]] inline clev::expected<void>
82 set_req_resend_tick(nng_duration d) noexcept
83 {
84 return set_option<opt::req_resend_tick>(d);
85 }
86
88
89 // TODO: use me
90 [[nodiscard]] inline clev::expected<const char*>
91 get_sock_name() const noexcept
92 {
93 return get_option<opt::sockname>();
94 }
95
96 [[nodiscard]] inline clev::expected<nng_duration>
97 get_recv_timeout() const noexcept
98 {
99 return get_option<opt::recvtimeo>();
100 }
101
102 [[nodiscard]] inline clev::expected<nng_duration>
103 get_send_timeout() const noexcept
104 {
105 return get_option<opt::sendtimeo>();
106 }
107
108 [[nodiscard]] inline clev::expected<nng_duration>
109 get_req_resend_time() const noexcept
110 {
111 return get_option<opt::req_resend_time>();
112 }
113
114 [[nodiscard]] inline clev::expected<nng_duration>
115 get_req_resend_tick() const noexcept
116 {
117 return get_option<opt::req_resend_tick>();
118 }
119
120private:
121 template<opt opt_v, nng_value_c nng_value_t>
122 [[nodiscard]] inline clev::expected<void> set_option(nng_value_t val)
123 {
125 }
126
127 template<opt opt_v>
128 [[nodiscard]] inline clev::expected<opt_to_nng_type_t<opt_v>>
129 get_option() const
130 {
131 return opt_getter<opt_v, nng_type>{}(parent::v);
132 }
133};
134
135} // namespace nngxx
136
137static_assert(ownxx_own_is_really_needed_v);
expected(value_t &&) -> expected< value_t >
Definition aio.h:35
value_type v
Definition value.h:71
value(value_type v) noexcept
Definition value.h:42
clev::expected< nng_duration > get_recv_timeout() const noexcept
Definition value.h:97
clev::expected< void > set_send_timeout(nng_duration d) noexcept
Definition value.h:70
clev::expected< nng_duration > get_req_resend_tick() const noexcept
Definition value.h:115
clev::expected< const char * > get_sock_name() const noexcept
Definition value.h:91
parent::value_type nng_type
Definition value.h:51
clev::value< nng_t > parent
Definition value.h:47
clev::expected< void > set_req_resend_tick(nng_duration d) noexcept
Definition value.h:82
static bool is_valid(nng_type v) noexcept
Definition value.h:53
clev::expected< nng_duration > get_send_timeout() const noexcept
Definition value.h:103
clev::expected< nng_duration > get_req_resend_time() const noexcept
Definition value.h:109
clev::expected< void > set_req_resend_time(nng_duration d) noexcept
Definition value.h:76
clev::expected< void > set_recv_timeout(nng_duration d) noexcept
Definition value.h:64