Shamrock
2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shambase
include
shambase
logs
msgformat.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
19
#include "
shambase/aliases_int.hpp
"
20
#include "
shambase/print.hpp
"
21
#include "
shambase/string.hpp
"
22
23
namespace
shambase::logs
{
24
26
// Log message formatting
28
37
inline
std::string
format_message
() {
return
""
; }
38
48
template
<
typename
T,
typename
...
Types
>
49
std::string
format_message
(T
var1
,
Types
...
var2
);
50
59
template
<
typename
...
Types
>
60
inline
std::string
format_message
(std::string s,
Types
...
var2
) {
61
return
s +
" "
+
format_message
(
var2
...);
62
}
63
76
template
<
typename
T,
typename
...
Types
>
77
inline
std::string
format_message
(T
var1
,
Types
...
var2
) {
78
// Special case for string literals
79
if
constexpr
(std::is_same_v<T, const char *>) {
80
// Convert the string literal to a std::string and concatenate it with the formatted
81
// string from the remaining arguments
82
return
std::string(
var1
) +
" "
+
format_message
(
var2
...);
83
}
84
// Special case for pointer types
85
else
if
constexpr
(std::is_pointer_v<T>) {
86
// Convert the pointer to a void pointer, format it as a hexadecimal string, and
87
// concatenate it with the formatted string from the remaining arguments
88
return
shambase::format(
"{} "
,
static_cast<
const
void
*
>
(
var1
))
89
+
format_message
(
var2
...);
90
}
91
92
else
{
93
// General case for other types
94
// Format the argument as a string and concatenate it with the formatted string from the
95
// remaining arguments
96
return
shambase::format(
"{} "
,
var1
) +
format_message
(
var2
...);
97
}
98
}
99
100
}
// namespace shambase::logs
aliases_int.hpp
shambase::logs
Namespace containing logs utils.
Definition
loglevel.hpp:24
shambase::logs::format_message
std::string format_message()
Formats an empty log message.
Definition
msgformat.hpp:37
shambase::throw_with_loc
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
Definition
exception.hpp:132
print.hpp
string.hpp
Generated on Wed May 13 2026 13:21:49 for Shamrock by
1.9.8