Skip to main content

The reflection.h File Reference

C++ header file with declarations for the µTest++ reflection utilities. More...

Included Headers

#include <string_view>

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_os_plus::micro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacemicro_os_plus::micro_test_plus::reflection

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

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...

constexpr std::string_viewtype_name (void)

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

Description

C++ header file with declarations for the µTest++ reflection utilities.

This header provides the declarations for the reflection utilities used within the µTest++ framework. It defines interfaces for obtaining source location information and extracting type names at compile time, supporting advanced diagnostics and reporting capabilities.

The reflection utilities include a local implementation of source_location for environments lacking C++20 standard support, as well as functions for extracting concise type names using compiler-specific macros such as __PRETTY_FUNCTION__. These facilities enable precise identification of code locations and types in test reports, enhancing the clarity and professionalism of diagnostic output.

All definitions reside within the micro_os_plus::micro_test_plus::reflection namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

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
nameThe 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.

type_name()

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

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
TThe 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.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE&#95;1&#95;0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
47
48#ifndef MICRO_TEST_PLUS_REFLECTION_H_
49#define MICRO_TEST_PLUS_REFLECTION_H_
50
51// ----------------------------------------------------------------------------
52
53#ifdef __cplusplus
54
55// ----------------------------------------------------------------------------
56
57#include <string_view>
58
59#if defined(__cpp_lib_source_location)
60#include <source_location>
61#endif
62
63// ----------------------------------------------------------------------------
64
65#if defined(__GNUC__)
66#pragma GCC diagnostic push
67#pragma GCC diagnostic ignored "-Wpadded"
68#pragma GCC diagnostic ignored "-Waggregate-return"
69#if defined(__clang__)
70#pragma clang diagnostic ignored "-Wc++98-compat"
71#pragma clang diagnostic ignored "-Wunknown-warning-option"
72#endif
73#endif
74
76{
77 // --------------------------------------------------------------------------
78
96 namespace reflection
97 {
98 // ------------------------------------------------------------------------
99
100#if defined(__cpp_lib_source_location)
114 using source_location = std::source_location;
115#else
137 {
138 public:
146 [[nodiscard]] static constexpr auto
147 current (
148#if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
149 const char* file = __builtin_FILE (),
150 unsigned int line = __builtin_LINE ()
151#else
152 const char* file = "unknown", unsigned int line = {}
153#endif
154 ) noexcept;
155
163 [[nodiscard]] constexpr auto
164 file_name (void) const noexcept;
165
173 [[nodiscard]] constexpr auto
174 line (void) const noexcept;
175
176 private:
180 const char* file_{ "unknown" };
181
185 unsigned int line_{};
186 };
187
188#endif
189
197 const char*
198 short_name (const char* name);
199
200 // TODO: update for the new namespaces.
201
211 template <class T>
212 [[nodiscard]] constexpr auto
213 type_name (void) -> std::string_view;
214
215 // ------------------------------------------------------------------------
216 } // namespace reflection
217
218 // --------------------------------------------------------------------------
219} // namespace micro_os_plus::micro_test_plus
220
221#if defined(__GNUC__)
222#pragma GCC diagnostic pop
223#endif
224
225// ----------------------------------------------------------------------------
226
227#endif // __cplusplus
228
229// ----------------------------------------------------------------------------
230
231#endif // MICRO_TEST_PLUS_REFLECTION_H_
232
233// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.