Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
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
18
20#include "shambase/print.hpp"
22#include <type_traits>
23#include <string>
24
25namespace shambase::logs {
26
28 // Log message formatting
30
39 inline std::string format_message() { return ""; }
40
50 template<typename T, typename... Types>
51 std::string format_message(T var1, Types... var2);
52
61 template<typename... Types>
62 inline std::string format_message(std::string s, Types... var2) {
63 return s + " " + format_message(var2...);
64 }
65
78 template<typename T, typename... Types>
79 inline std::string format_message(T var1, Types... var2) {
80 // Special case for string literals
81 if constexpr (std::is_same_v<T, const char *>) {
82 // Convert the string literal to a std::string and concatenate it with the formatted
83 // string from the remaining arguments
84 return std::string(var1) + " " + format_message(var2...);
85 }
86 // Special case for pointer types
87 else if constexpr (std::is_pointer_v<T>) {
88 // Convert the pointer to a void pointer, format it as a hexadecimal string, and
89 // concatenate it with the formatted string from the remaining arguments
90 return sham::format("{} ", static_cast<const void *>(var1)) + format_message(var2...);
91 }
92
93 else {
94 // General case for other types
95 // Format the argument as a string and concatenate it with the formatted string from the
96 // remaining arguments
97 return sham::format("{} ", var1) + format_message(var2...);
98 }
99 }
100
101} // namespace shambase::logs
Core formatting functions: format, vformat, and format_printf.
Namespace containing logs utils.
Definition loglevel.hpp:24
std::string format_message()
Formats an empty log message.
Definition msgformat.hpp:39