cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
method_name_view.h
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
// IWYU pragma: no_include <typeindex>
23
24
#include <cstddef>
25
#include <functional>
26
#include <string>
27
#include <string_view>
28
29
#include <fmt/base.h>
30
#include <fmt/format.h>
31
32
#include "
msgpack_rpc/messages/method_name.h
"
33
34
namespace
msgpack_rpc::messages
{
35
39
class
MethodNameView
{
40
public
:
49
MethodNameView
(
// NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
50
const
MethodName
&
name
) noexcept
51
:
name_
(
name
.name()) {
52
// Validation is done in MethodName.
53
}
54
63
MethodNameView
(
// NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
64
const
std::string&
name
)
65
:
name_
(
name
) {
66
// TODO Add a validation of UTF-8.
67
}
68
77
MethodNameView
(
// NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
78
std::string_view
name
)
79
:
name_
(
name
) {
80
// TODO Add a validation of UTF-8.
81
}
82
92
MethodNameView
(
const
char
*
name
, std::size_t size) :
name_
(
name
, size) {
93
// TODO Add a validation of UTF-8.
94
}
95
104
MethodNameView
(
// NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
105
const
char
*
name
)
106
:
name_
(
name
) {
107
// TODO Add a validation of UTF-8.
108
}
109
115
explicit
operator
MethodName
()
const
{
return
MethodName
(
name_
); }
116
122
[[nodiscard]] std::string_view
name
() const noexcept {
return
name_
; }
123
124
private
:
126
std::string_view
name_
;
127
};
128
137
[[nodiscard]]
inline
bool
operator==
(
138
MethodNameView
left,
MethodNameView
right)
noexcept
{
139
return
left.name() == right.name();
140
}
141
150
[[nodiscard]]
inline
bool
operator!=
(
151
MethodNameView
left,
MethodNameView
right)
noexcept
{
152
return
left.name() != right.name();
153
}
154
155
}
// namespace msgpack_rpc::messages
156
157
namespace
fmt
{
158
163
template
<>
164
class
formatter<
msgpack_rpc
::messages::MethodNameView>
165
:
public
formatter<std::string_view> {
166
public
:
174
format_context::iterator
format
(
175
const
msgpack_rpc::messages::MethodNameView
& val,
176
format_context& context)
const
{
177
return
formatter<std::string_view>::format(val.
name
(), context);
178
}
179
};
180
181
}
// namespace fmt
182
183
namespace
std
{
184
188
template
<>
189
struct
hash<
msgpack_rpc
::messages::MethodNameView> {
190
public
:
197
std::size_t
operator()
(
198
const
msgpack_rpc::messages::MethodNameView
& value)
const
{
199
return
string_view_hash_
(value.
name
());
200
}
201
202
private
:
204
std::hash<std::string_view>
string_view_hash_
{};
205
};
206
207
}
// namespace std
fmt::formatter< msgpack_rpc::messages::MethodNameView >::format
format_context::iterator format(const msgpack_rpc::messages::MethodNameView &val, format_context &context) const
Format a value.
Definition
method_name_view.h:174
msgpack_rpc::messages::MethodNameView
Class of method names.
Definition
method_name_view.h:39
msgpack_rpc::messages::MethodNameView::MethodNameView
MethodNameView(const std::string &name)
Constructor.
Definition
method_name_view.h:63
msgpack_rpc::messages::MethodNameView::MethodNameView
MethodNameView(const MethodName &name) noexcept
Constructor.
Definition
method_name_view.h:49
msgpack_rpc::messages::MethodNameView::MethodNameView
MethodNameView(const char *name, std::size_t size)
Constructor.
Definition
method_name_view.h:92
msgpack_rpc::messages::MethodNameView::MethodNameView
MethodNameView(std::string_view name)
Constructor.
Definition
method_name_view.h:77
msgpack_rpc::messages::MethodNameView::name
std::string_view name() const noexcept
Get the method name.
Definition
method_name_view.h:122
msgpack_rpc::messages::MethodNameView::name_
std::string_view name_
Method name.
Definition
method_name_view.h:126
msgpack_rpc::messages::MethodNameView::MethodNameView
MethodNameView(const char *name)
Constructor.
Definition
method_name_view.h:104
msgpack_rpc::messages::MethodName
Class of method names.
Definition
method_name.h:35
msgpack_rpc::messages::MethodName::MethodName
MethodName(std::string name)
Constructor.
Definition
method_name.h:45
method_name.h
Definition of MethodName class.
fmt
Namespace of fmt library.
Definition
uri.h:113
msgpack_rpc::messages
Namespace of messages.
Definition
buffer_view.h:24
msgpack_rpc::messages::operator!=
bool operator!=(const MethodName &left, const MethodName &right) noexcept
Compare two method names.
Definition
method_name.h:127
msgpack_rpc::messages::operator==
bool operator==(const MethodName &left, const MethodName &right) noexcept
Compare two method names.
Definition
method_name.h:114
msgpack_rpc
Namespace of cpp-msgpack-rpc library.
Definition
i_address.h:26
std
STL namespace.
std::hash< msgpack_rpc::messages::MethodNameView >::operator()
std::size_t operator()(const msgpack_rpc::messages::MethodNameView &value) const
Calculate the hash number of a value.
Definition
method_name_view.h:197
std::hash< msgpack_rpc::messages::MethodNameView >::string_view_hash_
std::hash< std::string_view > string_view_hash_
Hash of string_view.
Definition
method_name_view.h:204
include
msgpack_rpc
messages
method_name_view.h
Generated on
for cpp-msgpack-rpc by
1.18.0