get rid of fmt dependency since we are on C++23

This commit is contained in:
irisz64
2025-07-22 11:30:37 +02:00
parent 9b169825ee
commit 8549d5a21c
173 changed files with 452 additions and 83654 deletions

View File

@@ -7,7 +7,7 @@ void Options::SetValue<std::string>(const std::string &key, const std::string &f
template <>
void Options::SetValue<float>(const std::string &key, const std::string &field, const float &value) {
structure[key][field] = fmt::format("{:.2f}", value);
structure[key][field] = std::format("{:.2f}", value);
}
template <>

View File

@@ -22,7 +22,7 @@ struct Options {
structure["cpu"]["type"] = "interpreter";
if(!file.generate(structure))
Util::panic("Couldn't generate settings' INI!");
panic("Couldn't generate settings' INI!");
}
static Options &GetInstance() {
@@ -37,7 +37,7 @@ struct Options {
void Apply() {
if(!file.write(structure))
Util::panic("Could not modify options on disk!");
panic("Could not modify options on disk!");
}
private:
mINI::INIFile file;

View File

@@ -1,7 +1,6 @@
#pragma once
#include <common.hpp>
#include <fmt/color.h>
#include <fmt/core.h>
#include <print>
#include <string>
#if !defined(NDEBUG) && !defined(_WIN32)
#include <dlfcn.h>
@@ -16,94 +15,46 @@ static constexpr auto globalLogLevel = Trace;
static constexpr auto globalLogLevel = Info;
#endif
template <LogLevel messageType = Info, typename... Args>
void print(const std::string &fmt, Args... args) {
template <LogLevel messageType = Info, class... Args>
void print(const std::format_string<Args...> fmt, Args... args) {
if (messageType >= globalLogLevel) {
#ifndef _WIN32
if (messageType == Error) {
fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt::runtime(fmt), args...);
} else if (messageType == Warn) {
fmt::print(fg(fmt::color::yellow), fmt::runtime(fmt), args...);
} else if (messageType == Info || messageType == Always) {
fmt::print(fmt::runtime(fmt), args...);
} else if (messageType <= Debug) {
#ifndef NDEBUG
fmt::print(fmt::runtime(fmt), args...);
#endif
}
#else
if (messageType <= Debug) {
#ifndef NDEBUG
fmt::print(fmt::runtime(fmt), args...);
std::println(fmt, std::forward<Args>(args)...);
#endif
} else {
fmt::print(fmt::runtime(fmt), args...);
std::println(fmt, std::forward<Args>(args)...);
}
#endif
}
}
template <typename... Args>
void panic(const std::string &fmt, Args... args) {
print<Error>("[FATAL] " + fmt + "\n", args...);
exit(-1);
}
template <typename... Args>
void error(const std::string &fmt, Args... args) {
print<Error>("[ERROR] " + fmt + "\n", args...);
}
template <typename... Args>
void warn(const std::string &fmt, Args... args) {
print<Warn>("[WARN] " + fmt + "\n", args...);
}
template <typename... Args>
void info(const std::string &fmt, Args... args) {
print("[INFO] " + fmt + "\n", args...);
}
template <typename... Args>
void debug(const std::string &fmt, Args... args) {
print<Debug>("[DEBUG] " + fmt + "\n", args...);
}
template <typename... Args>
void trace(const std::string &fmt, Args... args) {
print<Trace>("[TRACE] " + fmt + "\n", args...);
}
template <typename... Args>
void always(const std::string &fmt, Args... args) {
print<Always>(fmt + "\n", args...);
}
template <typename... Args>
void panic_trace(const std::string &fmt, Args... args) {
#if !defined(NDEBUG) && !defined(_WIN32)
Dl_info info;
auto tmp = fmt::format(fmt::runtime(fmt + '\n'), args...);
tmp += "Called by:\n";
if (dladdr(__builtin_return_address(0), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(1), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(2), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(3), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(4), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(5), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
if (dladdr(__builtin_return_address(6), &info))
tmp += fmt::format("\t-> {}\n", info.dli_sname);
print<Error>("[FATAL TRACE] " + tmp);
exit(-1);
#else
panic(fmt, args...);
#endif
}
#define panic(fmt, ...) do \
{ \
Util::print<Util::Error>("[FATAL] " fmt, __VA_ARGS__); \
exit(-1); \
} while(0)
#define error(fmt, ...) do \
{ \
Util::print<Util::Error>("[ERROR] " fmt, __VA_ARGS__); \
} while(0)
#define warn(fmt, ...) do \
{ \
Util::print<Util::Warn>("[WARN] " fmt, __VA_ARGS__); \
} while(0)
#define info(fmt, ...) do \
{ \
Util::print<Util::Info>("[INFO] " fmt, __VA_ARGS__); \
} while(0)
#define debug(fmt, ...) do \
{ \
Util::print<Util::Debug>("[DEBUG] " fmt, __VA_ARGS__); \
} while(0)
#define trace(fmt, ...) do \
{ \
Util::print<Util::Trace>("[TRACE] " fmt, __VA_ARGS__); \
} while(0)
#define always(fmt, ...) do \
{ \
Util::print<Util::Always>(fmt, __VA_ARGS__); \
} while(0)
} // namespace Util