mimic++ v9.2.1
Loading...
Searching...
No Matches
boost-stacktrace.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024 - 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_EXT_STACKTRACE_BOOST_STACKTRACE_HPP
7#define MIMICPP_EXT_STACKTRACE_BOOST_STACKTRACE_HPP
8
9#include "mimic++/Fwd.hpp"
11
12#ifndef MIMICPP_DETAIL_IS_MODULE
13 #if __has_include(<boost/stacktrace.hpp>)
14 #include <boost/stacktrace.hpp>
15 #else
16 #error "The boost::stacktrace backend is explicitly enabled, but the the required include-file can not be found."
17 #endif
18
19 #include <limits>
20 #include <string>
21#endif
22
24{
25 using type = boost::stacktrace::stacktrace;
26};
27
28template <>
29struct mimicpp::util::stacktrace::backend_traits<boost::stacktrace::stacktrace>
30{
31 using Backend = boost::stacktrace::stacktrace;
32
33 [[nodiscard]]
34 static Backend current(std::size_t const skip, std::size_t const max) noexcept
35 {
36 MIMICPP_ASSERT(skip < std::numeric_limits<std::size_t>::max() - max, "Skip + max is too high.");
37
38 return Backend{skip + 1, max};
39 }
40
41 [[nodiscard]]
42 static Backend current(std::size_t const skip)
43 {
44 MIMICPP_ASSERT(skip < std::numeric_limits<std::size_t>::max(), "Skip is too high.");
45
46 return Backend{skip + 1, std::numeric_limits<std::size_t>::max()};
47 }
48
49 [[nodiscard]]
50 static std::size_t size(Backend const& stacktrace)
51 {
52 return stacktrace.size();
53 }
54
55 [[nodiscard]]
56 static bool empty(Backend const& stacktrace)
57 {
58 return stacktrace.empty();
59 }
60
61 [[nodiscard]]
62 static std::string description(Backend const& stacktrace, std::size_t const at)
63 {
64 return stacktrace[at].name();
65 }
66
67 [[nodiscard]]
68 static std::string source_file(Backend const& stacktrace, std::size_t const at)
69 {
70 return stacktrace[at].source_file();
71 }
72
73 [[nodiscard]]
74 static std::size_t source_line(Backend const& stacktrace, std::size_t const at)
75 {
76 return stacktrace[at].source_line();
77 }
78};
79
80#endif
#define MIMICPP_ASSERT(condition, msg)
Definition Config.hpp:51
Definition Fwd.hpp:447
static Backend current(std::size_t const skip, std::size_t const max) noexcept
Definition boost-stacktrace.hpp:34
static bool empty(Backend const &stacktrace)
Definition boost-stacktrace.hpp:56
static std::size_t source_line(Backend const &stacktrace, std::size_t const at)
Definition boost-stacktrace.hpp:74
static std::size_t size(Backend const &stacktrace)
Definition boost-stacktrace.hpp:50
static std::string description(Backend const &stacktrace, std::size_t const at)
Definition boost-stacktrace.hpp:62
boost::stacktrace::stacktrace Backend
Definition boost-stacktrace.hpp:31
static Backend current(std::size_t const skip)
Definition boost-stacktrace.hpp:42
static std::string source_file(Backend const &stacktrace, std::size_t const at)
Definition boost-stacktrace.hpp:68
Trait type for stacktrace backends.
Definition Fwd.hpp:453
Definition Stacktrace.hpp:529
NullBackend type
Definition Stacktrace.hpp:530