Sen API
Sen Libraries
Loading...
Searching...
No Matches
source_location.h
Go to the documentation of this file.
1// === source_location.h ===============================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_BASE_SOURCE_LOCATION_H
9#define SEN_CORE_BASE_SOURCE_LOCATION_H
10
11#include <string_view>
12#include <tuple> // for std::ignore
13
14namespace sen::impl
15{
16
19template <typename T, size_t s>
20constexpr size_t getFilenameOffset(const T (&str)[s], size_t i = s - 1) noexcept
21{
22 return (str[i] == '/' || str[i] == '\\') ? i + 1 : i > 0 ? getFilenameOffset(str, i - 1) : 0;
23}
24
26template <typename T>
27constexpr size_t getFilenameOffset(T (&str)[1]) noexcept
28{
29 std::ignore = str;
30 return 0;
31}
32
34template <typename T, T v>
35struct ConstexprValue
36{
37 static constexpr const T value = v;
38};
39
42#define SEN_SL_CONSTEXPR_VAL(exp) ::sen::impl::ConstexprValue<decltype(exp), exp>::value
43
44} // namespace sen::impl
45
46namespace sen
47{
48
51
54{
55 std::string_view fileName {"file name not set"};
56 int lineNumber {-1};
57 std::string_view functionName {"function name not set"};
58};
59
62#define SEN_SL() \
63 ::sen::SourceLocation \
64 { \
65 std::string_view {&__FILE__[SEN_SL_CONSTEXPR_VAL(::sen::impl::getFilenameOffset(__FILE__))]}, __LINE__, \
66 std::string_view(__FUNCTION__) \
67 }
68
70
71} // namespace sen
72
73#endif // SEN_CORE_BASE_SOURCE_LOCATION_H
std::string_view fileName
Definition source_location.h:55
std::string_view functionName
Definition source_location.h:57
int lineNumber
Definition source_location.h:56
Represents a location in source code.
Definition source_location.h:54
Definition assert.h:17