cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
source_location_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#include <cstdint>
23#include <string_view>
24
25namespace msgpack_rpc::logging {
26
31public:
41 constexpr SourceLocationView(std::string_view file_path, std::uint32_t line,
42 std::string_view function) noexcept
44
50 [[nodiscard]] constexpr std::string_view file_path() const noexcept {
51 return file_path_;
52 }
53
59 [[nodiscard]] constexpr std::uint32_t line() const noexcept {
60 return line_;
61 }
62
68 [[nodiscard]] constexpr std::string_view function() const noexcept {
69 return function_;
70 }
71
72private:
74 std::string_view file_path_;
75
77 std::uint32_t line_;
78
80 std::string_view function_;
81};
82
83} // namespace msgpack_rpc::logging
84
86#define MSGPACK_RPC_CURRENT_FILE_PATH __FILE__
87
89#define MSGPACK_RPC_CURRENT_LINE __LINE__
90
91#ifdef MSGPACK_RPC_DOCUMENTATION
97#define MSGPACK_RPC_CURRENT_FUNCTION <implementation defined strings>
98#elif __GNUC__ // GCC and Clang
99#define MSGPACK_RPC_CURRENT_FUNCTION __func__
100#elif _MSC_VER // MSVC
101#define MSGPACK_RPC_CURRENT_FUNCTION __FUNCSIG__
102#else // fallback (C++ standard)
103#define MSGPACK_RPC_CURRENT_FUNCTION __func__
104#endif
105
107#define MSGPACK_RPC_CURRENT_SOURCE_LOCATION() \
108 ::msgpack_rpc::logging::SourceLocationView( \
109 std::string_view(MSGPACK_RPC_CURRENT_FILE_PATH), /*NOLINT*/ \
110 static_cast<std::uint32_t>(MSGPACK_RPC_CURRENT_LINE), \
111 std::string_view(MSGPACK_RPC_CURRENT_FUNCTION)) /*NOLINT*/
std::string_view function_
Function name.
constexpr std::uint32_t line() const noexcept
Get the line number.
constexpr std::string_view file_path() const noexcept
Get the file path.
constexpr SourceLocationView(std::string_view file_path, std::uint32_t line, std::string_view function) noexcept
Constructor.
constexpr std::string_view function() const noexcept
Get the function name.
Namespace of logging.
Definition i_log_sink.h:27