| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | TTS - Tiny Test System | ||
| 4 | Copyright : TTS Contributors & Maintainers | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #include <tts/tools/text.hpp> | ||
| 11 | |||
| 12 | namespace tts::_ | ||
| 13 | { | ||
| 14 | class source_location | ||
| 15 | { | ||
| 16 | public: | ||
| 17 | 72 | [[nodiscard]] static auto current(char const* file = __builtin_FILE(), | |
| 18 | int line = __builtin_LINE()) noexcept | ||
| 19 | { | ||
| 20 | // __builtin_FILE() uses '\' on Windows, '/' elsewhere - must check both. | ||
| 21 | 72 | int offset = 0; | |
| 22 | 72 | auto slash = strrchr(file, '/'); | |
| 23 | 72 | auto bslash = strrchr(file, '\\'); | |
| 24 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
72 | auto end = (bslash && (!slash || bslash > slash)) ? bslash : slash; |
| 25 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if(end) offset = static_cast<int>(end - file + 1); |
| 26 | |||
| 27 | 72 | source_location that {}; | |
| 28 | 72 | that.desc_ = text {"[%s:%d]", file + offset, line}; | |
| 29 | |||
| 30 | 72 | return that; | |
| 31 | } | ||
| 32 | |||
| 33 | 72 | decltype(auto) data() const | |
| 34 | { | ||
| 35 | 72 | return desc_.data(); | |
| 36 | } | ||
| 37 | |||
| 38 | template<_::stream OS> friend OS& operator<<(OS& os, source_location const& s) | ||
| 39 | { | ||
| 40 | return os << s.desc_; | ||
| 41 | } | ||
| 42 | |||
| 43 | private: | ||
| 44 | text desc_ {"[unknown:?]"}; | ||
| 45 | }; | ||
| 46 | } | ||
| 47 |