4#include <classes/Colour.h>
5#include <sections/Misc.h>
29 void WriteToConsole(
const char* message);
30 void WriteToLog(
const char* message);
33 template<
typename Ty>
concept StandardLogable =
requires(std::ostream & os, Ty arg)
35 { os << arg } -> std::same_as<std::ostream&>;
39 template<
typename Ty>
concept TypeHasLogFunction =
requires(Ty obj)
41 { obj.LogStr() } -> std::same_as<std::string>;
45 template<
typename Ty>
struct DependentFalse : std::false_type {};
49 std::string ProcessArg(Ty&& arg)
52 if constexpr(std::is_pointer_v<std::remove_cvref_t<Ty>>)
56 return ProcessArg(*arg);
59 std::ostringstream os{};
60 os <<
"Nullptr of type: [" <<
typeid(Ty).name() <<
']';
61 return std::move(os).str();
65 else if constexpr (TypeHasLogFunction<Ty>)
71 else if constexpr (StandardLogable<Ty>)
73 std::ostringstream os{};
76 return std::move(os).str();
82 static_assert(DependentFalse<Ty>::value,
"Invalid type passed to Util::Internal::ProcessArg(), It is recommended not to use internal functions");
87 template<
typename... Args>
88 std::string ProcessArgs(Args&&... args)
90 return (ProcessArg(std::forward<Args>(args)) + ... +
"");
93 template<
typename Ty>
concept LogableBase = Internal::StandardLogable<Ty> || Internal::TypeHasLogFunction<Ty>;
94 template<
typename Ty>
concept Logable = LogableBase<Ty> || (LogableBase<std::remove_cv_t<std::remove_pointer_t<std::remove_cvref_t<Ty>>>>);
139 requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
145 std::string message = Internal::ProcessArgs(std::forward<Args>(
args)...);
146 Internal::WriteToConsole(message.c_str());
189 template<
typename... Args>
190 requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
193 std::string message = Internal::ProcessArgs(
"[PB_Util::Log()]: ", std::forward<Args>(
args)...,
'\n');
194 Internal::WriteToConsole(message.c_str());
195 Internal::WriteToLog(message.c_str());
202 requires (Internal::Logable<std::remove_cvref_t<Args>> && ...)
203 inline void PrintLn(Args&&... args)
205 Print(std::forward<Args>(args)...,
'\n');
208 template<
typename Ty, std::ranges::range Container_Ty,
typename Cargo_Ty = std::ranges::range_value_t<Container_Ty>>
209 requires Internal::Logable<Cargo_Ty>
210 inline void Log(Ty&& name,
const Container_Ty& container)
213 std::ostringstream os{};
214 os <<
"[PB_Util::Log]: \"" << Internal::ProcessArg(name) <<
"\"\n{\n";
216 unsigned counter = 0;
217 for (
const auto& item : container)
219 std::string itemStr = Internal::ProcessArg(item);
220 os <<
'\t' << std::setw(4) << std::left << counter <<
" | " << itemStr <<
'\n';
225 std::string message = os.str();
228 Internal::WriteToConsole(message.c_str());
229 Internal::WriteToLog(message.c_str());
void Print(Args &&... args)
Prints the message to the console.
Definition Log.h:140
Colour
Representation of each color and its corresponding Win32 console color code. Other operating systems ...
Definition Colour.h:16
@ Default
The default colour of the console.
void Log(Args &&... args)
Logs the message to the log file and console.
Definition Log.h:191
void SetConsoleColor(Colour col)
Sets the console to display text with a certain color.
Mathmatical vector class.
Definition Vec.h:216