Enrollment 28.2.0
Loading...
Searching...
No Matches
SourceLocation Class Reference

Class to capture the source location of an error or exception. More...

#include <SourceLocation.h>

Collaboration diagram for SourceLocation:

Public Member Functions

std::string FileName () const
 Get the name of the file where the exception occurred.
std::string FunctionName () const
 Get the name of the function where the exception occurred.
constexpr int Line () const
 Get the line number where the exception occurred.
 SourceLocation (const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
 Constructor to initialize a source location.
std::string ToString () const
 Creates string representation of SourceLocation.

Detailed Description

Class to capture the source location of an error or exception.

This struct serves as a pre-C++20 replacement for std::source_location, which is used to capture and store information about the source location where an exception was thrown.

Constructor & Destructor Documentation

◆ SourceLocation()

SourceLocation ( const char * file = __builtin_FILE(),
const char * function = __builtin_FUNCTION(),
int line = __builtin_LINE() )
inlineexplicit

Constructor to initialize a source location.

This constructor initializes a SourceLocation object with the file name, function name, and line number. In C++ the values are typically captured using compiler-provided built-in macros like __builtin_FILE(), __builtin_FUNCTION(), and __builtin_LINE().

Parameters
fileThe name of the source file
functionThe name of the function
lineThe line number within the file

Member Function Documentation

◆ FileName()

std::string FileName ( ) const
inlinenodiscard

Get the name of the file where the exception occurred.

This function returns the file name (path) where the exception was thrown.

Returns
file name.

◆ FunctionName()

std::string FunctionName ( ) const
inlinenodiscard

Get the name of the function where the exception occurred.

This function returns the name of the function in which the exception was thrown.

Returns
function name.

◆ Line()

int Line ( ) const
inlinenodiscardconstexpr

Get the line number where the exception occurred.

This function returns the line number from where the exception was thrown.

Returns
line number of the exception.

◆ ToString()

std::string ToString ( ) const
inlinenodiscard

Creates string representation of SourceLocation.

Format is file:line 'function'

Returns
string representation of SourceLocation

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