Skip to main content

The reflection Namespace Reference

Reflection utilities for the µTest++ testing framework. More...

Definition

namespace micro_os_plus::micro_test_plus::reflection { ... }

Classes Index

classsource_location

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

Functions Index

const char *short_name (const char *name)

Extract a short type or function name from a fully qualified name. More...

template <class T>
constexpr std::string_viewtype_name (void)

Extract the type name from the __PRETTY_FUNCTION__ macro. More...

Description

Reflection utilities for the µTest++ testing framework.

The reflection namespace provides facilities for obtaining source location information and type names at compile time, thereby supporting advanced reporting and diagnostics within the µTest++ framework.

It includes a local implementation of source_location for environments lacking C++20 standard support, as well as utilities for extracting concise type names from compiler-specific macros such as __PRETTY_FUNCTION__.

All definitions within this namespace are intended to facilitate advanced reflection and reporting capabilities.

Functions

short_name()

const char * micro_os_plus::micro_test_plus::reflection::short_name (const char * name)

Extract a short type or function name from a fully qualified name.

Parameters
name

The fully qualified name as a C-string.

Returns

A pointer to the short name within the input string.

This function extracts the short name from a given file path by locating the final folder separator ('/'). If a separator is found, it returns a pointer to the character immediately following it, effectively providing the file or folder name. If no separator is present, the original input string is returned. This utility is useful for reporting concise file or folder names in test output.

Definition at line 128 of file micro-test-plus.cpp.

128 short_name (const char* name)
129 {
130#pragma GCC diagnostic push
131#if defined(__clang__)
132#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
133#endif
134 const char* p = strrchr (name, '/');
135 if (p != nullptr)
136 return p + 1;
137 else
138 return name;
139#pragma GCC diagnostic pop
140 }

Referenced by micro_os_plus::micro_test_plus::test_reporter::output_fail_prefix_.

type_name()

template <class T>
std::string_view micro_os_plus::micro_test_plus::reflection::type_name (void)
nodiscard constexpr

Extract the type name from the __PRETTY_FUNCTION__ macro.

This function template parses the compiler-specific __PRETTY_FUNCTION__ macro to extract a concise type name for the template parameter T.

The implementation is compiler-dependent and may require adjustment for different toolchains. It is primarily intended for internal use within the µTest++ framework to support improved diagnostics and reporting.

Template Parameters
T

The type whose name is to be extracted.

Parameters

None.

Returns

A std::string_view containing the extracted type name.

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

133 type_name (void) -> std::string_view
134 {
135#if defined(__clang__)
136#pragma GCC diagnostic push
137#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
138 // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
139 // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]);
140 return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 };
141#pragma GCC diagnostic pop
142#elif defined(__GNUC__)
143 // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
144 // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
145 return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 };
146#else
147#error "Unsupported compiler"
148 return "Unsupported compiler";
149#endif
150 }

Referenced by micro_os_plus::micro_test_plus::test_reporter::operator<<.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.