micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
reflection.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * 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 be
9 * obtained from https://opensource.org/licenses/mit.
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.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_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#endif
72#endif
73
74// =============================================================================
75
77{
78 // --------------------------------------------------------------------------
79
97 namespace reflection
98 {
99 // ------------------------------------------------------------------------
100
101#if defined(__cpp_lib_source_location)
115 using source_location = std::source_location;
116#else
138 {
139 public:
147 [[nodiscard]] static constexpr source_location
148 current (
149#if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
150 const char* file = __builtin_FILE (),
151 unsigned int line = __builtin_LINE ()
152#else
153 const char* file = "unknown", unsigned int line = {}
154#endif
155 ) noexcept;
156
164 [[nodiscard]] constexpr auto
165 file_name (void) const noexcept;
166
174 [[nodiscard]] constexpr auto
175 line (void) const noexcept;
176
177 private:
181 const char* file_{ "unknown" };
182
186 unsigned int line_{};
187 };
188
189#endif
190
198 const char*
199 short_name (const char* name) noexcept;
200
210 template <class T>
211 [[nodiscard]] constexpr auto
212 type_name (void) -> std::string_view;
213
214 // ------------------------------------------------------------------------
215 } // namespace reflection
216
217 // --------------------------------------------------------------------------
218} // namespace micro_os_plus::micro_test_plus
219
220#if defined(__GNUC__)
221#pragma GCC diagnostic pop
222#endif
223
224// ----------------------------------------------------------------------------
225
226#endif // __cplusplus
227
228// ============================================================================
229// Templates & constexpr implementations.
230
232
233// ----------------------------------------------------------------------------
234
235#endif // MICRO_TEST_PLUS_REFLECTION_H_
236
237// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:138
unsigned int line_
The line number where the source location was captured.
Definition reflection.h:186
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.
const char * file_
The file name where the source location was captured.
Definition reflection.h:181
static constexpr source_location current(const char *file="unknown", unsigned int line={}) noexcept
Obtain the current source location.
Reflection utilities for the µTest++ testing framework.
constexpr auto type_name(void) -> std::string_view
Extract the type name from the __PRETTY_FUNCTION__ macro.
const char * short_name(const char *name) noexcept
Extract a short type or function name from a fully qualified name.
Primary namespace for the µTest++ testing framework.
C++ header file with inline implementations for the µTest++ reflection utilities.