xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
stack_frame.h
Go to the documentation of this file.
1 #pragma once
5 #include <cstdint>
6 #include <limits>
7 #include "../object.h"
8 #include "../ustring.h"
9 
11 namespace xtd {
13  namespace diagnostics {
15  class stack_trace;
17 
29  class stack_frame : public object {
30  public:
32  stack_frame();
35  explicit stack_frame(size_t skip_frame);
38  explicit stack_frame(bool need_file_info);
42  stack_frame(size_t skip_frame, bool need_file_info);
46  stack_frame(const xtd::ustring& file_name, uint32_t line_number);
51  stack_frame(const xtd::ustring& file_name, uint32_t line_number, const xtd::ustring& method_name);
57  stack_frame(const xtd::ustring& file_name, uint32_t line_number, const xtd::ustring& method_name, uint32_t column_number);
63  stack_frame(const xtd::ustring& file_name, uint32_t line_number, uint32_t column_number);
69  stack_frame(const xtd::ustring& file_name, uint32_t line_number, const xtd::ustring& method_name, uint32_t column_number, uint32_t offset);
71  stack_frame(const stack_frame&) = default;
72  stack_frame(stack_frame&&) = default;
73  stack_frame& operator=(const stack_frame&) = default;
74  bool operator==(const stack_frame& sf) const {return file_name_ == sf.file_name_ && file_line_number_ == sf.file_line_number_ && method_name_ == sf.method_name_ && file_column_number_ == sf.file_column_number_ && offset_ == sf.offset_;}
75  bool operator!=(const stack_frame& sf) const {return !operator==(sf);}
77 
80  static stack_frame empty() noexcept;
81 
97  virtual uint32_t get_file_column_number() const;
98 
114  virtual uint32_t get_file_line_number() const;
115 
131  virtual const xtd::ustring& get_file_name() const;
132 
148  virtual const xtd::ustring& get_method() const;
149 
165  virtual uint32_t get_offset() const;
166 
169  xtd::ustring to_string() const noexcept override;
170 
172  friend std::ostream& operator<<(std::ostream& os, const xtd::diagnostics::stack_frame& stack_frame) noexcept {return os << stack_frame.to_string();}
174 
177  static constexpr const uint32_t OFFSET_UNKNOWN = std::numeric_limits<uint32_t>::max();
178 
179  private:
180  friend class stack_trace;
181  static std::vector<stack_frame> get_stack_frames(const xtd::ustring& str, size_t skip_frames, bool need_file_info);
182 
183  xtd::ustring file_name_;
184  uint32_t file_line_number_ = 0;
185  xtd::ustring method_name_;
186  uint32_t file_column_number_ = 0;
187  uint32_t offset_ = OFFSET_UNKNOWN;
188  };
189  }
190 }
191 
201 #define current_stack_frame_ \
202 xtd::diagnostics::stack_frame {__FILE__, __LINE__, __func__}
203 
213 #define csf_ current_stack_frame_
214 
215 #define add_current_stack_frame_(...) \
216 __VA_ARGS__ __VA_ARGS_COMMA__(__VA_ARGS__) current_stack_frame_
virtual const xtd::ustring & get_file_name() const
Gets the file name that contains the code that is executing. This information is typically extracted ...
virtual uint32_t get_file_column_number() const
Gets the column number in the file that contains the code that is executing. This information is typi...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents a stack trace, which is an ordered collection of one or more stack frames.
Definition: stack_trace.h:32
virtual uint32_t get_file_line_number() const
Gets the line number in the file that contains the code that is executing. This information is typica...
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
xtd::ustring to_string() const noexcept override
Builds a readable representation of the stack trace.
stack_frame()
Initializes a new instance of the xtd::diagnostics::stack_frame class.
virtual const xtd::ustring & get_method() const
Gets the method in which the frame is executing.
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:29
static stack_frame empty() noexcept
Return an empty stack frame.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
static constexpr const uint32_t OFFSET_UNKNOWN
Defines the value that is returned from the get_offset() method when the offset is unknown...
Definition: stack_frame.h:177
virtual uint32_t get_offset() const
Gets the offset from the start of the code for the method that is being executed. ...