cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
method_exception.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 <exception>
23#include <memory>
24#include <type_traits>
25#include <utility>
26
27#include <msgpack.hpp>
28
29#include "msgpack_rpc/impl/msgpack_rpc_export.h"
30
31namespace msgpack_rpc::methods {
32
39class MSGPACK_RPC_EXPORT MethodException : public std::exception {
40public:
41 // Exceptions must be exported in libraries. If not exported, exceptions
42 // cannot be caught correctly.
43
53 template <typename T>
54 explicit MethodException(T&& object,
55 std::enable_if_t<!std::is_same_v<std::decay_t<T>, MethodException>,
56 void*> /*for SFINAE*/
57 = nullptr)
58 : zone_(std::make_shared<msgpack::zone>()),
59 object_(std::forward<T>(object), *zone_) {}
60
66 [[nodiscard]] const msgpack::object& object() const noexcept;
67
73 [[nodiscard]] const char* what() const noexcept override;
74
79
84
90 MethodException& operator=(const MethodException&) noexcept;
91
97 MethodException& operator=(MethodException&&) noexcept;
98
100 ~MethodException() noexcept override;
101
102private:
104 std::shared_ptr<msgpack::zone> zone_;
105
107 msgpack::object object_;
108};
109
110} // namespace msgpack_rpc::methods
std::shared_ptr< msgpack::zone > zone_
Zone in msgpack library.
msgpack::object object_
Object in msgpack library.
const msgpack::object & object() const noexcept
Get the object in msgpack library.
MethodException(T &&object, std::enable_if_t<!std::is_same_v< std::decay_t< T >, MethodException >, void * >=nullptr)
Constructor.
Namespace of methods in MessagePack-RPC.
STL namespace.