mirror of
https://github.com/libAthena/athena.git
synced 2025-07-31 17:35:38 +00:00
<iostream> injects a static constructor into every translation unit that includes the header--even if nothing from the header is used. This can result in minor initial program slowdown, as all of these constructors need to run before main() can execute. Instead, we can use <ostream>, which includes all of the necessary machinery that we need.
75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
#include "athena/Global.hpp"
|
|
#include "athena/Utility.hpp"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
#define FMT_STRING_ALIAS 1
|
|
#define FMT_ENFORCE_COMPILE_STRING 1
|
|
#define FMT_USE_GRISU 0
|
|
#include <fmt/format.h>
|
|
|
|
std::ostream& operator<<(std::ostream& os, const athena::SeekOrigin& origin) {
|
|
switch (origin) {
|
|
case athena::SeekOrigin::Begin:
|
|
os << "Begin";
|
|
break;
|
|
|
|
case athena::SeekOrigin::Current:
|
|
os << "Current";
|
|
break;
|
|
|
|
case athena::SeekOrigin::End:
|
|
os << "End";
|
|
break;
|
|
}
|
|
|
|
return os;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, const athena::Endian& endian) {
|
|
switch (endian) {
|
|
case athena::Endian::Little:
|
|
os << "LittleEndian";
|
|
break;
|
|
|
|
case athena::Endian::Big:
|
|
os << "BigEndian";
|
|
break;
|
|
}
|
|
|
|
return os;
|
|
}
|
|
|
|
static void __defaultExceptionHandler(athena::error::Level level, const char* file, const char* function, int line,
|
|
fmt::string_view fmt, fmt::format_args args) {
|
|
std::string levelStr;
|
|
switch (level) {
|
|
case athena::error::Level::Warning:
|
|
levelStr = "[WARNING] ";
|
|
break;
|
|
case athena::error::Level::Error:
|
|
levelStr = "[ERROR ] ";
|
|
break;
|
|
case athena::error::Level::Fatal:
|
|
levelStr = "[FATAL ] ";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
std::string msg = fmt::internal::vformat(fmt, args);
|
|
std::cerr << levelStr << " " << file << " " << function << "(" << line << "): " << msg << std::endl;
|
|
}
|
|
|
|
static atEXCEPTION_HANDLER g_atExceptionHandler = __defaultExceptionHandler;
|
|
|
|
atEXCEPTION_HANDLER atGetExceptionHandler() { return g_atExceptionHandler; }
|
|
|
|
void atSetExceptionHandler(atEXCEPTION_HANDLER func) {
|
|
if (func)
|
|
g_atExceptionHandler = func;
|
|
else
|
|
g_atExceptionHandler = __defaultExceptionHandler;
|
|
}
|