micro-test-plus
6.0.1
µTest++ Testing Framework
Toggle main menu visibility
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
41
42
#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
43
#define MICRO_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
44
45
// ----------------------------------------------------------------------------
46
47
#if defined(__cplusplus)
48
49
// ----------------------------------------------------------------------------
50
51
#if __has_include("micro-os-plus/project-config.h")
52
#include "micro-os-plus/project-config.h"
53
#endif
// __has_include("micro-os-plus/project-config.h")
54
55
#if __has_include("micro-os-plus/micro-test-plus-defines.h")
56
#include "micro-os-plus/micro-test-plus-defines.h"
57
#endif
// __has_include("micro-os-plus/micro-test-plus-defines.h")
58
59
#include <string_view>
60
// Defines `__cpp_lib_source_location` regardless of the headers included
61
// before this one, so that all translation units choose the same
62
// `source_location` type.
63
#include <version>
64
65
#if defined(__cpp_lib_source_location)
66
#include <source_location>
67
#endif
// defined(__cpp_lib_source_location)
68
69
// ----------------------------------------------------------------------------
70
71
#if defined(__GNUC__)
72
#pragma GCC diagnostic push
73
74
#pragma GCC diagnostic ignored "-Wpadded"
75
#pragma GCC diagnostic ignored "-Waggregate-return"
76
#if defined(__clang__)
77
#pragma clang diagnostic ignored "-Wc++98-compat"
78
#endif
// defined(__clang__)
79
#endif
// defined(__GNUC__)
80
81
// ============================================================================
82
83
namespace
micro_os_plus::micro_test_plus
84
{
85
// --------------------------------------------------------------------------
86
101
namespace
reflection
102
{
103
// ------------------------------------------------------------------------
104
105
#if defined(__cpp_lib_source_location)
106
118
using
source_location
= std::source_location;
119
120
#else
121
142
class
source_location
143
{
144
public
:
152
[[nodiscard]]
static
constexpr
source_location
153
current
(
154
#
if
(__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
155
const
char
* file = __builtin_FILE (),
156
unsigned
int
line
= __builtin_LINE ()
157
#
else
158
const
char
* file =
"unknown"
,
unsigned
int
line
= {}
159
#endif
// (__has_builtin(__builtin_FILE) and __has_builtin(__builtin_LINE))
160
)
noexcept
;
161
169
[[nodiscard]]
constexpr
auto
170
file_name
(
void
)
const
noexcept
;
171
179
[[nodiscard]]
constexpr
auto
180
line
(
void
)
const
noexcept
;
181
182
private
:
189
const
char
*
file_
{
"unknown"
};
190
197
unsigned
int
line_
{};
198
};
199
200
#endif
// defined(__cpp_lib_source_location)
201
218
template
<
class
T>
219
[[nodiscard]]
constexpr
auto
220
type_name
(
void
) -> std::string_view;
221
222
// ------------------------------------------------------------------------
223
}
// namespace reflection
224
225
// --------------------------------------------------------------------------
226
}
// namespace micro_os_plus::micro_test_plus
227
228
#if defined(__GNUC__)
229
#pragma GCC diagnostic pop
230
#endif
// defined(__GNUC__)
231
232
// ----------------------------------------------------------------------------
233
234
#endif
// defined(__cplusplus)
235
236
// ============================================================================
237
// Templates, inlines & constexpr implementations.
238
239
#include "
inlines/reflection-inlines.h
"
240
241
// ----------------------------------------------------------------------------
242
243
#endif
// MICRO_OS_PLUS_MICRO_TEST_PLUS_REFLECTION_H_
244
245
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::reflection::source_location
Local implementation of source location information for diagnostics.
Definition
reflection.h:143
micro_os_plus::micro_test_plus::reflection::source_location::line_
unsigned int line_
The line number where the source location was captured.
Definition
reflection.h:197
micro_os_plus::micro_test_plus::reflection::source_location::file_name
constexpr auto file_name(void) const noexcept
Returns the file name associated with this source location.
Definition
reflection-inlines.h:101
micro_os_plus::micro_test_plus::reflection::source_location::line
constexpr auto line(void) const noexcept
Returns the line number associated with this source location.
Definition
reflection-inlines.h:112
micro_os_plus::micro_test_plus::reflection::source_location::file_
const char * file_
The file name where the source location was captured.
Definition
reflection.h:189
micro_os_plus::micro_test_plus::reflection::source_location::current
static constexpr source_location current(const char *file="unknown", unsigned int line={}) noexcept
Returns the current source location.
Definition
reflection-inlines.h:87
micro_os_plus::micro_test_plus::reflection
Reflection utilities for the µTest++ testing framework.
Definition
deprecated.h:2255
micro_os_plus::micro_test_plus::reflection::type_name
constexpr auto type_name(void) -> std::string_view
Extracts the type name from the __PRETTY_FUNCTION__ identifier.
Definition
reflection-inlines.h:149
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
Definition
check-result.h:76
reflection-inlines.h
C++ header file with inline implementations for the µTest++ reflection utilities.
include
micro-os-plus
micro-test-plus
reflection.h
Generated by
1.18.0