micro-test-plus 5.0.1
µ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_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
49#define MICRO_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
50
51// ----------------------------------------------------------------------------
52
53#if defined(__cplusplus)
54
55// ----------------------------------------------------------------------------
56
57#if __has_include("micro-os-plus/project-config.h")
58#include "micro-os-plus/project-config.h"
59#endif // __has_include("micro-os-plus/project-config.h")
60
61#if __has_include("micro-os-plus/micro-test-plus-defines.h")
62#include "micro-os-plus/micro-test-plus-defines.h"
63#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
64
65#include <string_view>
66
67#if defined(__cpp_lib_source_location)
68#include <source_location>
69#endif // defined(__cpp_lib_source_location)
70
71// ----------------------------------------------------------------------------
72
73#if defined(__GNUC__)
74#pragma GCC diagnostic push
75
76#pragma GCC diagnostic ignored "-Wpadded"
77#pragma GCC diagnostic ignored "-Waggregate-return"
78#if defined(__clang__)
79#pragma clang diagnostic ignored "-Wc++98-compat"
80#endif // defined(__clang__)
81#endif // defined(__GNUC__)
82
83// =============================================================================
84
86{
87 // --------------------------------------------------------------------------
88
106 namespace reflection
107 {
108 // ------------------------------------------------------------------------
109
110#if defined(__cpp_lib_source_location)
111
125 using source_location = std::source_location;
126
127#else
128
150 {
151 public:
159 [[nodiscard]] static constexpr source_location
160 current (
161#if (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
162 const char* file = __builtin_FILE (),
163 unsigned int line = __builtin_LINE ()
164#else
165 const char* file = "unknown", unsigned int line = {}
166#endif // (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
167 ) noexcept;
168
176 [[nodiscard]] constexpr auto
177 file_name (void) const noexcept;
178
186 [[nodiscard]] constexpr auto
187 line (void) const noexcept;
188
189 private:
193 const char* file_{ "unknown" };
194
198 unsigned int line_{};
199 };
200
201#endif // defined(__cpp_lib_source_location)
202
210 const char*
211 short_name (const char* name) noexcept;
212
222 template <class T>
223 [[nodiscard]] constexpr auto
224 type_name (void) -> std::string_view;
225
226 // ------------------------------------------------------------------------
227 } // namespace reflection
228
229 // --------------------------------------------------------------------------
230} // namespace micro_os_plus::micro_test_plus
231
232#if defined(__GNUC__)
233#pragma GCC diagnostic pop
234#endif // defined(__GNUC__)
235
236// ----------------------------------------------------------------------------
237
238#endif // defined(__cplusplus)
239
240// ============================================================================
241// Templates, inlines & constexpr implementations.
242
244
245// ----------------------------------------------------------------------------
246
247#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
248
249// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:150
unsigned int line_
The line number where the source location was captured.
Definition reflection.h:198
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:193
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.