Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
SourceLocation.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2022, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#if defined(HAS_SOURCE_LOCATION) && __has_builtin(__builtin_source_location)
23// this is used by fully compatible compilers like gcc
24#include <source_location>
25
26#elif defined(HAS_EXPERIMENTAL_SOURCE_LOCATION)
27// this is used by clang on linux where source_location is still not out of
28// experimental headers
29#include <experimental/source_location>
30
31#else
32
33#include <cstddef>
34#include <string_view>
35#endif
36
37namespace util {
38
39#if defined(HAS_SOURCE_LOCATION) && __has_builtin(__builtin_source_location)
40using SourceLocationType = std::source_location;
41
42#elif defined(HAS_EXPERIMENTAL_SOURCE_LOCATION)
43using SourceLocationType = std::experimental::source_location;
44
45#else
53 char const* file_;
54 std::size_t line_;
55
56public:
63 constexpr SourceLocation(char const* file, std::size_t line) : file_{file}, line_{line}
64 {
65 }
66
72 constexpr std::string_view
73 file_name() const
74 {
75 return file_;
76 }
77
83 constexpr std::size_t
84 line() const
85 {
86 return line_;
87 }
88};
89using SourceLocationType = SourceLocation;
90#define SOURCE_LOCATION_OLD_API
91
92#endif
93
94} // namespace util
95
96#if defined(SOURCE_LOCATION_OLD_API)
97#define CURRENT_SRC_LOCATION util::SourceLocationType(__FILE__, __LINE__)
98#else
99#define CURRENT_SRC_LOCATION util::SourceLocationType::current()
100#endif
A class representing the source location of the current code.
Definition SourceLocation.hpp:52
constexpr std::string_view file_name() const
Get the file name.
Definition SourceLocation.hpp:73
constexpr SourceLocation(char const *file, std::size_t line)
Construct a new Source Location object.
Definition SourceLocation.hpp:63
constexpr std::size_t line() const
Get the line number.
Definition SourceLocation.hpp:84
This namespace contains various utilities.
Definition AccountUtils.hpp:30