micro-test-plus
4.1.0
µTest++ Testing Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
reflection-inlines.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_INLINES_H_
49
#define MICRO_TEST_PLUS_REFLECTION_INLINES_H_
50
51
// ----------------------------------------------------------------------------
52
53
#ifdef __cplusplus
54
55
// ----------------------------------------------------------------------------
56
57
#include <cstdint>
58
59
// ----------------------------------------------------------------------------
60
61
#if defined(__GNUC__)
62
#pragma GCC diagnostic push
63
#pragma GCC diagnostic ignored "-Waggregate-return"
64
#if defined(__clang__)
65
#pragma clang diagnostic ignored "-Wc++98-compat"
66
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
67
#endif
68
#endif
69
70
// ============================================================================
71
72
namespace
micro_os_plus::micro_test_plus
73
{
74
// --------------------------------------------------------------------------
75
76
namespace
reflection
77
{
78
// ------------------------------------------------------------------------
79
80
#if !defined(__cpp_lib_source_location)
81
90
constexpr
source_location
91
source_location::current
(
const
char
* file,
unsigned
int
line
)
noexcept
92
{
93
source_location
sl{};
94
sl.
file_
= file;
95
sl.
line_
=
line
;
96
return
sl;
97
}
98
104
constexpr
auto
105
source_location::file_name
(
void
)
const
noexcept
106
{
107
return
file_
;
108
}
109
115
constexpr
auto
116
source_location::line
(
void
)
const
noexcept
117
{
118
return
line_
;
119
}
120
121
#endif
122
143
template
<
class
T>
144
constexpr
auto
145
type_name
(
void
) -> std::string_view
146
{
147
const
std::string_view sv = __PRETTY_FUNCTION__;
148
#if defined(__clang__)
149
// Clang: "... [T = <typename>]"
150
// rfind('[') locates the opening bracket of "[T = ...]".
151
const
auto
start = sv.rfind (
'['
) + 5;
// skip "[T = "
152
const
auto
end = sv.rfind (
']'
);
153
#elif defined(__GNUC__)
154
// GCC: "... [with T = <typename>]" or, on some versions,
155
// "... [with T = <typename>; std::string_view = ...]"
156
// Search for "T = " explicitly to avoid landing on a later '='.
157
const
auto
t_eq = sv.find (
"T = "
);
158
const
auto
start = t_eq + 4;
// skip "T = "
159
const
auto
semi = sv.find (
';'
, start);
160
const
auto
end
161
= (semi != std::string_view::npos) ? semi : sv.rfind (
']'
);
162
#else
163
// Note: MSVC uses __FUNCSIG__ instead of __PRETTY_FUNCTION__.
164
// MSVC is not a supported target for this framework.
165
#error "Unsupported compiler"
166
#endif
167
return
sv.substr (start, end - start);
168
}
169
170
// ------------------------------------------------------------------------
171
}
// namespace reflection
172
173
// --------------------------------------------------------------------------
174
}
// namespace micro_os_plus::micro_test_plus
175
176
#if defined(__GNUC__)
177
#pragma GCC diagnostic pop
178
#endif
179
180
// ----------------------------------------------------------------------------
181
182
#endif
// __cplusplus
183
184
// ----------------------------------------------------------------------------
185
186
#endif
// MICRO_TEST_PLUS_REFLECTION_INLINES_H_
187
188
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::reflection::source_location
Local implementation of source location information for diagnostics.
Definition
reflection.h:138
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:186
micro_os_plus::micro_test_plus::reflection::source_location::file_name
constexpr auto file_name(void) const noexcept
Retrieve the file name associated with this source location.
Definition
reflection-inlines.h:105
micro_os_plus::micro_test_plus::reflection::source_location::line
constexpr auto line(void) const noexcept
Retrieve the line number associated with this source location.
Definition
reflection-inlines.h:116
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:181
micro_os_plus::micro_test_plus::reflection::source_location::current
static constexpr source_location current(const char *file="unknown", unsigned int line={}) noexcept
Obtain the current source location.
Definition
reflection-inlines.h:91
micro_os_plus::micro_test_plus::reflection
Reflection utilities for the µTest++ testing framework.
Definition
reflection-inlines.h:77
micro_os_plus::micro_test_plus::reflection::type_name
constexpr auto type_name(void) -> std::string_view
Extract the type name from the __PRETTY_FUNCTION__ macro.
Definition
reflection-inlines.h:145
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
include
micro-os-plus
micro-test-plus
inlines
reflection-inlines.h
Generated by
1.17.0