xtd 0.2.0
Loading...
Searching...
No Matches
xtd::diagnostics::source_location Class Reference
Inheritance diagram for xtd::diagnostics::source_location:
xtd::object

Definition

The xtd::diagnostics::source_location class represents certain information about the source code, such as file names, line numbers, and function names. Previously, functions that desire to obtain this information about the call site (for logging, testing, or debugging purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are expanded in the context of the caller. The xtd::diagnostics::source_location class provides a better alternative.

source_location()
Initializes a new instance of the xtd::diagnostics::source_location class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::diagnostics::source_location
Header
#include <xtd/diagnostics/source_location>
Namespace
xtd
Library
xtd.core
Remarks
The xtd::diagnostics::source_location is used by xtd::diagnostics::stack_frame and xtd::diagnostics::stack_trace.
The xtd::diagnostics::source_location is same as std::source_location.

Public Constructors

 source_location ()
 Initializes a new instance of the xtd::diagnostics::source_location class.
 

Public Properties

auto column () const noexcept -> xtd::size
 Gets the column number represented by this object.
 
auto file_name () const noexcept -> const xtd::string &
 Gets the name of the current source file represented by this object, represented as a null-terminated byte string.
 
auto function_name () const noexcept -> const xtd::string &
 Gets the name of the function associated with the position represented by this object, if any.
 
auto line () const noexcept -> xtd::size
 Gets the line number represented by this object.
 

Public Methods

auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
 

Public Static Methods

static auto current (const __xtd_source_location__ &value=__xtd_source_location__::current()) noexcept -> xtd::diagnostics::source_location
 Crates a new xtd::diagnostics::source_location object corresponding to the location of the call site.
 

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ source_location()

xtd::diagnostics::source_location::source_location ( )

Initializes a new instance of the xtd::diagnostics::source_location class.

Member Function Documentation

◆ column()

auto xtd::diagnostics::source_location::column ( ) const -> xtd::size
nodiscardnoexcept

Gets the column number represented by this object.

Returns
The column number represented by this object.
Remarks
Returns 0 when the column number is unknown.

◆ file_name()

auto xtd::diagnostics::source_location::file_name ( ) const -> const xtd::string &
nodiscardnoexcept

Gets the name of the current source file represented by this object, represented as a null-terminated byte string.

Returns
The name of the current source file represented by this object.
Remarks
Returns xtd::string::empty_string ("") when the source file is unknown.

◆ function_name()

auto xtd::diagnostics::source_location::function_name ( ) const -> const xtd::string &
nodiscardnoexcept

Gets the name of the function associated with the position represented by this object, if any.

Returns
If this object represents a position in a body of a function, returns a string corresponding to the name of the function; otherwise, an xtd::string::empty_string ("") is returned.

◆ line()

auto xtd::diagnostics::source_location::line ( ) const -> xtd::size
nodiscardnoexcept

Gets the line number represented by this object.

Returns
The line number represented by this object.
Remarks
Returns 0 when the line number is unknown.

◆ to_string()

auto xtd::diagnostics::source_location::to_string ( ) const -> xtd::string
nodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
object()=default
Create a new instance of the ultimate base class object.

Reimplemented from xtd::object.

◆ current()

static auto xtd::diagnostics::source_location::current ( const __xtd_source_location__ & value = __xtd_source_location__::current()) -> xtd::diagnostics::source_location
staticnodiscardnoexcept

Crates a new xtd::diagnostics::source_location object corresponding to the location of the call site.

Returns
The currentsouce location informations.
Remarks
If xtd::diagnostics::source_location::current is invoked directly (via a function call that names xtd::diagnostics::source_location::current), it returns a source_location object with implementation-defined values representing the location of the call. The values should be affected by the #line preprocessor directive in the same manner as the predefined macros __LINE__ and __FILE__.
If xtd::diagnostics::source_location::current is used in a default member initializer, the return value corresponds to the location of the constructor definition or aggregate initialization that initializes the data member.
If xtd::diagnostics::source_location::current is used in a default argument, the return value corresponds to the location of the call to xtd::diagnostics::source_location::current at the call site.
If xtd::diagnostics::source_location::current is invoked in any other manner, the return value is unspecified.
Note
xtd::diagnostics::source_location::current typically requires compiler's built-in implementation.

The documentation for this class was generated from the following file: