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// std
12#include <cstddef>
13#include <string_view>
14
15namespace sen::impl
16{
17
20constexpr size_t getFilenameOffset(const std::string_view str) noexcept
21{
22 const size_t pos = str.find_last_of("/\\");
23 return pos == std::string_view::npos ? 0 : pos + 1;
24}
25
27template <typename T, T v>
28struct ConstexprValue
29{
30 static constexpr const T value = v;
31};
32
35#define SEN_SL_CONSTEXPR_VAL(exp) ::sen::impl::ConstexprValue<decltype(exp), exp>::value
36
37} // namespace sen::impl
38
39namespace sen
40{
41
44
47{
48 std::string_view fileName {"file name not set"};
49 int lineNumber {-1};
50 std::string_view functionName {"function name not set"};
51};
52
53#ifdef WIN32
54# define SEN_PRETTY_FUNCTION_NAME __FUNCSIG__
55#else
56# define SEN_PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
57#endif
58
61#define SEN_SL() \
62 ::sen::SourceLocation \
63 { \
64 std::string_view {&__FILE__[SEN_SL_CONSTEXPR_VAL(::sen::impl::getFilenameOffset(__FILE__))]}, __LINE__, \
65 std::string_view(SEN_PRETTY_FUNCTION_NAME) \
66 }
67
69
70} // namespace sen
71
72#endif // SEN_CORE_BASE_SOURCE_LOCATION_H
std::string_view fileName
Definition source_location.h:48
std::string_view functionName
Definition source_location.h:50
int lineNumber
Definition source_location.h:49
Represents a location in source code.
Definition source_location.h:47
Definition assert.h:17