forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_location.h
76 lines (64 loc) · 2.68 KB
/
source_location.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2023 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Originally from https://github.com/paweldac/source_location
#ifndef BITCOIN_SOURCE_LOCATION_H
#define BITCOIN_SOURCE_LOCATION_H
#pragma once
#include <cstdint>
namespace nostd {
struct source_location {
public:
#if defined(__clang__) and (__clang_major__ >= 9)
static constexpr source_location current(const char* fileName = __builtin_FILE(),
const char* functionName = __builtin_FUNCTION(),
const uint_least32_t lineNumber = __builtin_LINE(),
const uint_least32_t columnOffset = __builtin_COLUMN()) noexcept
#elif defined(__GNUC__) and (__GNUC__ > 4 or (__GNUC__ == 4 and __GNUC_MINOR__ >= 8))
static constexpr source_location current(const char* fileName = __builtin_FILE(),
const char* functionName = __builtin_FUNCTION(),
const uint_least32_t lineNumber = __builtin_LINE(),
const uint_least32_t columnOffset = 0) noexcept
#else
static constexpr source_location current(const char* fileName = "unsupported",
const char* functionName = "unsupported",
const uint_least32_t lineNumber = 0,
const uint_least32_t columnOffset = 0) noexcept
#endif
{
return source_location(fileName, functionName, lineNumber, columnOffset);
}
source_location(const source_location&) = default;
source_location(source_location&&) = default;
constexpr const char* file_name() const noexcept
{
return fileName;
}
constexpr const char* function_name() const noexcept
{
return functionName;
}
constexpr uint_least32_t line() const noexcept
{
return lineNumber;
}
constexpr std::uint_least32_t column() const noexcept
{
return columnOffset;
}
private:
constexpr source_location(const char* fileName, const char* functionName, const uint_least32_t lineNumber,
const uint_least32_t columnOffset) noexcept
: fileName(fileName)
, functionName(functionName)
, lineNumber(lineNumber)
, columnOffset(columnOffset)
{
}
const char* fileName;
const char* functionName;
const std::uint_least32_t lineNumber;
const std::uint_least32_t columnOffset;
};
} // namespace nostd
#endif // BITCOIN_SOURCE_LOCATION_H