cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
method_name.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#include <cstddef>
23#include <string>
24#include <string_view>
25#include <utility>
26
27#include <fmt/base.h>
28#include <fmt/format.h>
29
30namespace msgpack_rpc::messages {
31
36public:
45 MethodName( // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
46 std::string name)
47 : name_(std::move(name)) {
48 // TODO Add a validation of UTF-8.
49 }
50
59 MethodName( // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
60 std::string_view name)
61 : name_(name) {
62 // TODO Add a validation of UTF-8.
63 }
64
74 MethodName( // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
75 const char* name, std::size_t size)
76 : name_(name, size) {
77 // TODO Add a validation of UTF-8.
78 }
79
88 MethodName( // NOLINT(google-explicit-constructor, hicpp-explicit-conversions)
89 const char* name)
90 : name_(name) {
91 // TODO Add a validation of UTF-8.
92 }
93
99 [[nodiscard]] std::string_view name() const noexcept { return name_; }
100
101private:
103 std::string name_;
104};
105
114[[nodiscard]] inline bool operator==(
115 const MethodName& left, const MethodName& right) noexcept {
116 return left.name() == right.name();
117}
118
127[[nodiscard]] inline bool operator!=(
128 const MethodName& left, const MethodName& right) noexcept {
129 return left.name() != right.name();
130}
131
132} // namespace msgpack_rpc::messages
133
134namespace fmt {
135
140template <>
141class formatter<msgpack_rpc::messages::MethodName>
142 : public formatter<std::string_view> {
143public:
151 format_context::iterator format(
153 format_context& context) const {
154 return formatter<std::string_view>::format(val.name(), context);
155 }
156};
157
158} // namespace fmt
format_context::iterator format(const msgpack_rpc::messages::MethodName &val, format_context &context) const
Format a value.
Class of method names.
Definition method_name.h:35
MethodName(const char *name)
Constructor.
Definition method_name.h:88
MethodName(const char *name, std::size_t size)
Constructor.
Definition method_name.h:74
MethodName(std::string_view name)
Constructor.
Definition method_name.h:59
std::string name_
Method name.
MethodName(std::string name)
Constructor.
Definition method_name.h:45
std::string_view name() const noexcept
Get the method name.
Definition method_name.h:99
Namespace of fmt library.
Definition uri.h:113
Namespace of messages.
Definition buffer_view.h:24
bool operator!=(const MethodName &left, const MethodName &right) noexcept
Compare two method names.
bool operator==(const MethodName &left, const MethodName &right) noexcept
Compare two method names.
Namespace of cpp-msgpack-rpc library.
Definition i_address.h:26
STL namespace.