Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
SourceLocation.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18
19#include <source_location>
20#include <string>
21
22namespace shambase {
28 std::string format_multiline(std::source_location loc);
29
36 std::string format_multiline(std::source_location loc, const std::string &stacktrace);
37
43 std::string format_one_line(std::source_location loc);
44
50 std::string format_one_line_func(std::source_location loc);
51} // namespace shambase
52
61struct SourceLocation {
62
63 using srcloc = std::source_location;
64
65 srcloc loc;
66
67 inline constexpr explicit SourceLocation(srcloc _loc = srcloc::current()) noexcept
68 : loc(_loc) {}
69
75 inline std::string format_multiline() const { return shambase::format_multiline(loc); }
76
83 inline std::string format_multiline(const std::string &stacktrace) const {
84 return shambase::format_multiline(loc, stacktrace);
85 }
86
92 inline std::string format_one_line() const { return shambase::format_one_line(loc); }
93
99 inline std::string format_one_line_func() const { return shambase::format_one_line_func(loc); }
100};
namespace for basic c++ utilities
std::string format_one_line_func(std::source_location loc)
format the location in a one liner with the function name displayed
std::string format_one_line(std::source_location loc)
format the location in a one liner
std::string format_multiline(std::source_location loc)
format the location in multiple lines
std::string format_one_line_func() const
format the location in a one liner with the function name displayed
std::string format_multiline() const
format the location in multiple lines
std::string format_multiline(const std::string &stacktrace) const
format the location in multiple lines with a given stacktrace
std::string format_one_line() const
format the location in a one liner