micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
micro_os_plus::micro_test_plus::reflection::source_location Class Reference

Local implementation of source location information for diagnostics. More...

#include <micro-os-plus/micro-test-plus.h>

Public Member Functions

constexpr auto file_name (void) const noexcept
 Retrieve the file name associated with this source location.
constexpr auto line (void) const noexcept
 Retrieve the line number associated with this source location.

Static Public Member Functions

static constexpr source_location current (const char *file="unknown", unsigned int line={}) noexcept
 Obtain the current source location.

Private Attributes

const char * file_ { "unknown" }
 The file name where the source location was captured.
unsigned int line_ {}
 The line number where the source location was captured.

Detailed Description

This class provides a lightweight, constexpr-compatible alternative to std::source_location for environments lacking C++20 standard support.

It enables retrieval of the file name and line number at the point of invocation, supporting enhanced diagnostics and reporting within the µTest++ framework.

The static current() method captures the current source location, using compiler built-ins where available, or defaulting to "unknown" and zero otherwise.

Since
3.0.0

Definition at line 137 of file reflection.h.

Member Function Documentation

◆ current()

source_location micro_os_plus::micro_test_plus::reflection::source_location::current ( const char * file = "unknown",
unsigned int line = {} )
staticnodiscardconstexprnoexcept
Parameters
fileThe file name (automatically provided by the compiler).
lineThe line number (automatically provided by the compiler).
Returns
A source_location instance with the captured information.

Returns a source_location instance representing the file name and line number at the point of invocation.

If supported by the compiler, uses built-in macros to capture this information; otherwise, defaults to "unknown" and zero.

Definition at line 91 of file reflection-inlines.h.

92 {
93 source_location sl{};
94 sl.file_ = file;
95 sl.line_ = line;
96 return sl;
97 }
constexpr auto line(void) const noexcept
Retrieve the line number associated with this source location.

References file_, line(), and line_.

Referenced by micro_os_plus::micro_test_plus::runner::operator=(), and micro_os_plus::micro_test_plus::subtest::operator=().

◆ file_name()

auto micro_os_plus::micro_test_plus::reflection::source_location::file_name ( void ) const
nodiscardconstexprnoexcept
Parameters
None.
Returns
The file name as a constant character pointer.

Returns the file name captured at the time this source_location instance was created.

Definition at line 105 of file reflection-inlines.h.

106 {
107 return file_;
108 }
const char * file_
The file name where the source location was captured.
Definition reflection.h:181

References file_.

Referenced by micro_os_plus::micro_test_plus::runner::abort(), micro_os_plus::micro_test_plus::reporter_human::output_fail_prefix_(), and micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_().

◆ line()

auto micro_os_plus::micro_test_plus::reflection::source_location::line ( void ) const
nodiscardconstexprnoexcept
Parameters
None.
Returns
The line number as an unsigned integer.

Returns the line number captured at the time this source_location instance was created.

Definition at line 116 of file reflection-inlines.h.

117 {
118 return line_;
119 }
unsigned int line_
The line number where the source location was captured.
Definition reflection.h:186

References line_.

Referenced by micro_os_plus::micro_test_plus::runner::abort(), current(), micro_os_plus::micro_test_plus::reporter_human::output_fail_prefix_(), and micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_().

Member Data Documentation

◆ file_

const char* micro_os_plus::micro_test_plus::reflection::source_location::file_ { "unknown" }
private

Definition at line 181 of file reflection.h.

181{ "unknown" };

Referenced by current(), and file_name().

◆ line_

unsigned int micro_os_plus::micro_test_plus::reflection::source_location::line_ {}
private

Definition at line 186 of file reflection.h.

186{};

Referenced by current(), and line().


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