CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
stack_trace.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_SYSTEM_STACK_TRACE_H
10#define CPPCOMMON_SYSTEM_STACK_TRACE_H
11
12#include "string/format.h"
13
14#include <sstream>
15#include <string>
16#include <vector>
17
19
22#define __STACK__ CppCommon::StackTrace()
23
24namespace CppCommon {
25
27
33{
34public:
36 struct Frame
37 {
38 void* address;
39 std::string module;
40 std::string function;
41 std::string filename;
42 int line;
43
45 std::string string() const
46 { std::stringstream ss; ss << *this; return ss.str(); }
47
49 friend std::ostream& operator<<(std::ostream& os, const Frame& frame);
50 };
51
52public:
54
57 explicit StackTrace(int skip = 0);
58 StackTrace(const StackTrace&) = default;
59 StackTrace(StackTrace&&) noexcept = default;
60 ~StackTrace() = default;
61
62 StackTrace& operator=(const StackTrace&) = default;
63 StackTrace& operator=(StackTrace&&) noexcept = default;
64
66 const std::vector<Frame>& frames() const noexcept { return _frames; }
67
69 std::string string() const
70 { std::stringstream ss; ss << *this; return ss.str(); }
71
73 friend std::ostream& operator<<(std::ostream& os, const StackTrace& stack_trace);
74
75private:
76 std::vector<Frame> _frames;
77};
78
81} // namespace CppCommon
82
83#include "stack_trace.inl"
84
85#endif // CPPCOMMON_SYSTEM_STACK_TRACE_H
Stack trace snapshot provider.
Definition stack_trace.h:33
std::string string() const
Get string from the current stack trace snapshot.
Definition stack_trace.h:69
StackTrace(StackTrace &&) noexcept=default
const std::vector< Frame > & frames() const noexcept
Get stack trace frames.
Definition stack_trace.h:66
friend std::ostream & operator<<(std::ostream &os, const StackTrace &stack_trace)
Output stack trace into the given output stream.
StackTrace(const StackTrace &)=default
Format string definition.
C++ Common project definitions.
Stack trace snapshot provider inline implementation.
std::string filename
Frame file name.
Definition stack_trace.h:41
std::string std::string function
< Frame module
Definition stack_trace.h:40
int line
Frame line number.
Definition stack_trace.h:42
std::string string() const
Get string from the current stack trace frame.
Definition stack_trace.h:45
void * address
Frame address.
Definition stack_trace.h:38
friend std::ostream & operator<<(std::ostream &os, const Frame &frame)
Output stack trace frame into the given output stream.