micro-test-plus 3.2.2
µ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 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
9 * be 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#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// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:137
unsigned int line_
The line number where the source location was captured.
Definition reflection.h:185
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.
static constexpr auto current(const char *file="unknown", unsigned int line={}) noexcept
Obtain the current source location.
const char * file_
The file name where the source location was captured.
Definition reflection.h:180
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)
Extract a short type or function name from a fully qualified name.
Primary namespace for the µTest++ testing framework.