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

Definition

The xtd::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::source_location class provides a better alternative.

Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
The xtd::source_location class represents certain information about the source code,...
Definition source_location.hpp:30
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::source_location
Header
#include <xtd/source_location>
Namespace
xtd
Library
xtd.core
Remarks
The xtd::source_location is used by xtd::diagnostics::stack_frame and xtd::diagnostics::stack_trace.
The xtd::source_location is same as std::source_location.

Public Constructors

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

Public Properties

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

Public Methods

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

Public Static Methods

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

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 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 size_t 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<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename 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<typename object_a_t , typename 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::source_location::source_location ( )

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

Member Function Documentation

◆ column()

xtd::size xtd::source_location::column ( ) const
noexcept

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()

const xtd::string & xtd::source_location::file_name ( ) const
noexcept

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()

const xtd::string & xtd::source_location::function_name ( ) const
noexcept

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()

xtd::size xtd::source_location::line ( ) const
noexcept

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()

xtd::string xtd::source_location::to_string ( ) const
overridevirtualnoexcept

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>
using namespace 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
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10

Reimplemented from xtd::object.

◆ current()

static source_location xtd::source_location::current ( const __xtd_source_location__ &  value = __xtd_source_location__::current())
staticnoexcept

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

Returns
The currentsouce location informations.
Remarks
If xtd::source_location::current is invoked directly (via a function call that names xtd::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::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::source_location::current is used in a default argument, the return value corresponds to the location of the call to xtd::source_location::current at the call site.
If xtd::source_location::current is invoked in any other manner, the return value is unspecified.
Note
xtd::source_location::current typically requires compiler's built-in implementation.

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