MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
stacktrace.hpp
1#ifndef MSTL_CORE_UTILITY_STACKTRACE_HPP__
2#define MSTL_CORE_UTILITY_STACKTRACE_HPP__
3#include "../container/vector.hpp"
4#include "../interface/istringify.hpp"
5#ifdef MSTL_PLATFORM_WINDOWS__
6#include "../async/mutex.hpp"
7#endif
9
10class MSTL_API stacktrace : public istringify<stacktrace> {
11public:
12 class frame : public istringify<frame> {
13 private:
14 void* address_;
15
16#ifdef MSTL_PLATFORM_WINDOWS__
17 static void ensure_initialized();
18 static mutex& dbghelp_mutex();
19#endif
20
21 public:
22 frame() : address_(nullptr) {}
23 explicit frame(void* addr) : address_(addr) {}
24
25 MSTL_NODISCARD void* address() const noexcept { return address_; }
26 MSTL_NODISCARD string name() const;
27
28 MSTL_NODISCARD bool operator ==(const frame& other) const noexcept {
29 return address_ == other.address_;
30 }
31 MSTL_NODISCARD bool operator !=(const frame& other) const noexcept {
32 return !(*this == other);
33 }
34
35 MSTL_NODISCARD string to_string() const;
36 };
37
38private:
39 vector<frame> frames_;
40
41public:
42 explicit stacktrace(size_t skip = 0, size_t max_depth = 64);
43
44 MSTL_NODISCARD size_t size() const noexcept { return frames_.size(); }
45 MSTL_NODISCARD bool empty() const noexcept { return frames_.empty(); }
46
47 MSTL_NODISCARD const frame& operator [](const size_t idx) const noexcept { return frames_[idx]; }
48 MSTL_NODISCARD frame& operator [](const size_t idx) noexcept { return frames_[idx]; }
49
50 MSTL_NODISCARD auto begin() const noexcept { return frames_.begin(); }
51 MSTL_NODISCARD auto end() const noexcept { return frames_.end(); }
52 MSTL_NODISCARD auto cbegin() const noexcept { return frames_.cbegin(); }
53 MSTL_NODISCARD auto cend() const noexcept { return frames_.cend(); }
54
55 MSTL_NODISCARD string to_string() const;
56};
57
59#endif // MSTL_CORE_UTILITY_STACKTRACE_HPP__
bool operator!=(const function< Res(Args...)> &f, nullptr_t null) noexcept
不等于空指针比较
bool operator==(const function< Res(Args...)> &f, nullptr_t null) noexcept
等于空指针比较
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr bool empty(const Container &cont) noexcept(noexcept(cont.empty()))
检查容器是否为空
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) size(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的大小
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cend(const Container &cont) noexcept(noexcept(cont.cend()))
获取const容器的const结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) begin(Container &cont) noexcept(noexcept(cont.begin()))
获取容器的起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cbegin(const Container &cont) noexcept(noexcept(cont.cbegin()))
获取const容器的const起始迭代器
MSTL互斥锁