mirror of https://github.com/libAthena/athena.git
Massive fmtlib refactor
This commit is contained in:
parent
f3852eb0d2
commit
478d75f1cb
|
@ -1,3 +1,6 @@
|
|||
[submodule "extern/lzokay"]
|
||||
path = extern/lzokay
|
||||
url = https://github.com/jackoalan/lzokay.git
|
||||
[submodule "extern/fmt"]
|
||||
path = extern/fmt
|
||||
url = https://github.com/fmtlib/fmt
|
||||
|
|
|
@ -84,7 +84,7 @@ add_library(athena-core
|
|||
target_include_directories(athena-core PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${ZLIB_INCLUDE_DIR}>)
|
||||
target_link_libraries(athena-core PUBLIC athena-libyaml)
|
||||
target_link_libraries(athena-core PUBLIC athena-libyaml fmt)
|
||||
|
||||
add_library(athena-sakura EXCLUDE_FROM_ALL
|
||||
src/athena/Sprite.cpp
|
||||
|
@ -191,7 +191,8 @@ foreach(p LIB INCLUDE CMAKE)
|
|||
endforeach()
|
||||
|
||||
# Define installs
|
||||
install(DIRECTORY include/ DESTINATION ${INSTALL_INCLUDE_DIR}/athena COMPONENT athena)
|
||||
install(DIRECTORY include DESTINATION ${INSTALL_INCLUDE_DIR}/athena COMPONENT athena)
|
||||
install(DIRECTORY extern/fmt/include DESTINATION ${INSTALL_INCLUDE_DIR}/fmt COMPONENT athena)
|
||||
install(TARGETS athena-core
|
||||
DESTINATION ${INSTALL_LIB_DIR} EXPORT AthenaTargets COMPONENT athena)
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
|
@ -208,7 +209,7 @@ endif()
|
|||
##################
|
||||
|
||||
# Add all targets to the build-tree export set
|
||||
export(TARGETS athena-core athena-libyaml FILE "${CMAKE_CURRENT_BINARY_DIR}/AthenaTargets.cmake")
|
||||
export(TARGETS athena-core athena-libyaml fmt FILE "${CMAKE_CURRENT_BINARY_DIR}/AthenaTargets.cmake")
|
||||
|
||||
# Export the package for use from the build-tree
|
||||
# (this registers the build-tree with a global CMake-registry)
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
|
||||
string(REPLACE -stdlib=libc++ "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
get_directory_property(ATDNA_DEFINES COMPILE_DEFINITIONS)
|
||||
list(REMOVE_ITEM ATDNA_DEFINES _GLIBCXX_DEBUG=1)
|
||||
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${ATDNA_DEFINES}")
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
add_subdirectory(lzokay)
|
||||
add_subdirectory(zlib)
|
||||
add_subdirectory(yaml)
|
||||
if(NOT TARGET fmt)
|
||||
add_subdirectory(fmt)
|
||||
endif()
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6bcc3fd21694b5634cc006915bd049cf460a9a8d
|
|
@ -1 +1 @@
|
|||
Subproject commit 343f9707f6ab2143d3455c93d8b7570a0ffcee97
|
||||
Subproject commit 671e2b98642f95aaf29251367791f28e5597a0a7
|
|
@ -9,17 +9,17 @@
|
|||
namespace athena::io {
|
||||
|
||||
template <class T>
|
||||
static inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0) {
|
||||
inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0) {
|
||||
return dna.DNATypeV();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0) {
|
||||
inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0) {
|
||||
return dna.DNAType();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline std::string ToYAMLString(const T& dna) {
|
||||
inline std::string ToYAMLString(const T& dna) {
|
||||
YAMLDocWriter docWriter(__GetDNAName(dna));
|
||||
|
||||
std::string res;
|
||||
|
@ -35,7 +35,7 @@ static inline std::string ToYAMLString(const T& dna) {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool FromYAMLString(T& dna, std::string_view str) {
|
||||
inline bool FromYAMLString(T& dna, std::string_view str) {
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
|
@ -46,7 +46,7 @@ static inline bool FromYAMLString(T& dna, std::string_view str) {
|
|||
}
|
||||
|
||||
template <class DNASubtype>
|
||||
static inline bool ValidateFromYAMLString(std::string_view str) {
|
||||
inline bool ValidateFromYAMLString(std::string_view str) {
|
||||
YAMLStdStringViewReaderState reader(str);
|
||||
YAMLDocReader docReader;
|
||||
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
|
||||
|
@ -55,7 +55,7 @@ static inline bool ValidateFromYAMLString(std::string_view str) {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
|
||||
inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
|
||||
YAMLDocWriter docWriter(__GetDNAName(dna));
|
||||
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
|
@ -66,8 +66,8 @@ static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
|
||||
void (T::*fn)(YAMLDocWriter& out) const) {
|
||||
inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
|
||||
void (T::*fn)(YAMLDocWriter& out) const) {
|
||||
YAMLDocWriter docWriter(__GetDNAName(dna));
|
||||
|
||||
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
|
||||
|
@ -78,7 +78,7 @@ static inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
|
|||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
|
||||
inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
|
@ -87,7 +87,7 @@ static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)(YAMLDocReader& in)) {
|
||||
inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)(YAMLDocReader& in)) {
|
||||
YAMLDocReader docReader;
|
||||
if (!docReader.parse(&fin))
|
||||
return false;
|
||||
|
@ -96,7 +96,7 @@ static inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (
|
|||
}
|
||||
|
||||
template <class T, typename NameT>
|
||||
static inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
|
||||
inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
|
||||
athena::io::FileReader r(filename);
|
||||
YAMLDocWriter docWriter(__GetDNAName(dna), r.isOpen() ? &r : nullptr);
|
||||
r.close();
|
||||
|
@ -109,7 +109,7 @@ static inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
|
|||
}
|
||||
|
||||
template <class DNASubtype>
|
||||
static inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin) {
|
||||
inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin) {
|
||||
YAMLDocReader reader;
|
||||
atUint64 pos = fin.position();
|
||||
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#include <iostream>
|
||||
#include "athena/Types.hpp"
|
||||
|
||||
#define FMT_STRING_ALIAS 1
|
||||
#define FMT_ENFORCE_COMPILE_STRING 1
|
||||
#define FMT_USE_GRISU 0
|
||||
#include <fmt/format.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
|
@ -142,8 +147,8 @@ inline constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
|
|||
} // namespace io
|
||||
} // namespace athena
|
||||
|
||||
typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* file, const char* function, int line,
|
||||
const char* fmt, ...);
|
||||
typedef void (*atEXCEPTION_HANDLER)(athena::error::Level level, const char* /*file*/, const char*, int /*line*/,
|
||||
fmt::string_view fmt, fmt::format_args args);
|
||||
|
||||
atEXCEPTION_HANDLER atGetExceptionHandler();
|
||||
/**
|
||||
|
@ -155,83 +160,54 @@ void atSetExceptionHandler(atEXCEPTION_HANDLER func);
|
|||
std::ostream& operator<<(std::ostream& os, const athena::SeekOrigin& origin);
|
||||
std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
template <typename First, typename... Rest>
|
||||
constexpr auto __FIRST_ARG__(First first, Rest...) { return first; }
|
||||
template <typename S, typename... Args>
|
||||
inline auto __make_args_checked__(const S& format_str, Args&&... args) {
|
||||
return fmt::internal::make_args_checked<Args...>(format_str, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define atDebug(fmt, ...) \
|
||||
#define atDebug(...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, __FIRST_ARG__(__VA_ARGS__), \
|
||||
__make_args_checked__(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
#else
|
||||
#define atDebug(fmt, ...)
|
||||
#define atDebug(...)
|
||||
#endif
|
||||
|
||||
#define atMessage(fmt, ...) \
|
||||
#define atMessage(...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, __FIRST_ARG__(__VA_ARGS__), \
|
||||
__make_args_checked__(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
|
||||
#define atWarning(fmt, ...) \
|
||||
#define atWarning(...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
if (__handler) { \
|
||||
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, __FIRST_ARG__(__VA_ARGS__), \
|
||||
__make_args_checked__(__VA_ARGS__)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define atError(fmt, ...) \
|
||||
#define atError(...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, __FIRST_ARG__(__VA_ARGS__), \
|
||||
__make_args_checked__(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
|
||||
#define atFatal(fmt, ...) \
|
||||
#define atFatal(...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, __FIRST_ARG__(__VA_ARGS__), \
|
||||
__make_args_checked__(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define atDebug(fmt...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
||||
} while (0)
|
||||
#else // _MSC_VER
|
||||
#define atDebug(fmt, ...)
|
||||
#endif // NDEBUG
|
||||
|
||||
#define atMessage(fmt...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
||||
} while (0)
|
||||
|
||||
#define atWarning(fmt...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
||||
} while (0)
|
||||
|
||||
#define atError(fmt...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
||||
} while (0)
|
||||
|
||||
#define atFatal(fmt...) \
|
||||
do { \
|
||||
atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
||||
if (__handler) \
|
||||
__handler(athena::error::Level::Fatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
||||
} while (0)
|
||||
#endif // defined(__GNUC__)
|
||||
|
|
|
@ -650,7 +650,7 @@ public:
|
|||
utf8proc_int32_t wc;
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -664,7 +664,7 @@ public:
|
|||
if (*buf) {
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -698,7 +698,7 @@ public:
|
|||
utf8proc_int32_t wc;
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -712,7 +712,7 @@ public:
|
|||
if (*buf) {
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -747,7 +747,7 @@ public:
|
|||
utf8proc_int32_t wc;
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -761,7 +761,7 @@ public:
|
|||
if (*buf) {
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return;
|
||||
}
|
||||
buf += len;
|
||||
|
|
|
@ -10,16 +10,16 @@
|
|||
#include "athena/Types.hpp"
|
||||
|
||||
namespace athena::utility {
|
||||
inline bool isEmpty(atInt8* buf, atUint32 size) { return !memcmp(buf, buf + 1, size - 1); }
|
||||
inline bool isEmpty(atInt8* buf, atUint32 size) { return !std::memcmp(buf, buf + 1, size - 1); }
|
||||
#if _WIN32
|
||||
constexpr bool isSystemBigEndian() { return false; }
|
||||
#else
|
||||
constexpr bool isSystemBigEndian() { return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; }
|
||||
#endif
|
||||
inline constexpr ::athena::Endian SystemEndian = isSystemBigEndian() ? Big : Little;
|
||||
inline constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? Little : Big;
|
||||
constexpr ::athena::Endian SystemEndian = isSystemBigEndian() ? Big : Little;
|
||||
constexpr ::athena::Endian NotSystemEndian = isSystemBigEndian() ? Little : Big;
|
||||
|
||||
inline atInt16 swap16(atInt16 val) {
|
||||
constexpr atInt16 swap16(atInt16 val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap16(val);
|
||||
#elif _WIN32
|
||||
|
@ -28,8 +28,8 @@ inline atInt16 swap16(atInt16 val) {
|
|||
return (val = (val << 8) | ((val >> 8) & 0xFF));
|
||||
#endif
|
||||
}
|
||||
inline atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
|
||||
inline atInt32 swap32(atInt32 val) {
|
||||
constexpr atUint16 swapU16(atUint16 val) { return (atUint16)swap16(val); }
|
||||
constexpr atInt32 swap32(atInt32 val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap32(val);
|
||||
#elif _WIN32
|
||||
|
@ -40,8 +40,8 @@ inline atInt32 swap32(atInt32 val) {
|
|||
return val;
|
||||
#endif
|
||||
}
|
||||
inline atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
|
||||
inline atInt64 swap64(atInt64 val) {
|
||||
constexpr atUint32 swapU32(atUint32 val) { return (atUint32)swap32(val); }
|
||||
constexpr atInt64 swap64(atInt64 val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap64(val);
|
||||
#elif _WIN32
|
||||
|
@ -54,89 +54,89 @@ inline atInt64 swap64(atInt64 val) {
|
|||
(((atInt64)(val)&0x000000000000FF00ULL) << 40) | (((atInt64)(val)&0x00000000000000FFULL) << 56))));
|
||||
#endif
|
||||
}
|
||||
inline atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
|
||||
inline float swapFloat(float val) {
|
||||
constexpr atUint64 swapU64(atUint64 val) { return (atUint64)swap64(val); }
|
||||
constexpr float swapFloat(float val) {
|
||||
union { float f; atInt32 i; } uval1 = {val};
|
||||
union { atInt32 i; float f; } uval2 = {swap32(uval1.i)};
|
||||
return uval2.f;
|
||||
}
|
||||
inline double swapDouble(double val) {
|
||||
constexpr double swapDouble(double val) {
|
||||
union { double f; atInt64 i; } uval1 = {val};
|
||||
union { atInt64 i; double f; } uval2 = {swap64(uval1.i)};
|
||||
return uval2.f;
|
||||
}
|
||||
inline atInt16 LittleInt16(atInt16& val) {
|
||||
if (athena::utility::isSystemBigEndian())
|
||||
constexpr atInt16 LittleInt16(atInt16& val) {
|
||||
if constexpr (athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap16(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint16 LittleUint16(atUint16& val) {
|
||||
constexpr atUint16 LittleUint16(atUint16& val) {
|
||||
atInt16 ret = val;
|
||||
LittleInt16(ret);
|
||||
val = ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atInt16 BigInt16(atInt16& val) {
|
||||
if (!athena::utility::isSystemBigEndian())
|
||||
constexpr atInt16 BigInt16(atInt16& val) {
|
||||
if constexpr (!athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap16(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint16 BigUint16(atUint16& val) {
|
||||
constexpr atUint16 BigUint16(atUint16& val) {
|
||||
atInt16 ret = val;
|
||||
BigInt16(ret);
|
||||
val = ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atInt32 LittleInt32(atInt32& val) {
|
||||
if (athena::utility::isSystemBigEndian())
|
||||
constexpr atInt32 LittleInt32(atInt32& val) {
|
||||
if constexpr (athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap32(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint32 LittleUint32(atUint32& val) {
|
||||
constexpr atUint32 LittleUint32(atUint32& val) {
|
||||
atInt32 ret = val;
|
||||
LittleInt32(ret);
|
||||
val = ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atInt32 BigInt32(atInt32& val) {
|
||||
if (!athena::utility::isSystemBigEndian())
|
||||
constexpr atInt32 BigInt32(atInt32& val) {
|
||||
if constexpr (!athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap32(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint32 BigUint32(atUint32& val) {
|
||||
constexpr atUint32 BigUint32(atUint32& val) {
|
||||
atInt32 ret = val;
|
||||
BigInt32(ret);
|
||||
val = ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atInt64 LittleInt64(atInt64& val) {
|
||||
if (athena::utility::isSystemBigEndian())
|
||||
constexpr atInt64 LittleInt64(atInt64& val) {
|
||||
if constexpr (athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap64(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint64 LittleUint64(atUint64& val) {
|
||||
constexpr atUint64 LittleUint64(atUint64& val) {
|
||||
atInt64 ret = val;
|
||||
LittleInt64(ret);
|
||||
val = ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atInt64 BigInt64(atInt64& val) {
|
||||
if (!athena::utility::isSystemBigEndian())
|
||||
constexpr atInt64 BigInt64(atInt64& val) {
|
||||
if constexpr (!athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swap64(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline atUint64 BigUint64(atUint64& val) {
|
||||
constexpr atUint64 BigUint64(atUint64& val) {
|
||||
atInt64 ret = val;
|
||||
BigInt64(ret);
|
||||
val = ret;
|
||||
|
@ -144,27 +144,27 @@ inline atUint64 BigUint64(atUint64& val) {
|
|||
return val;
|
||||
}
|
||||
|
||||
inline float LittleFloat(float val) {
|
||||
if (athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swapFloat(val);
|
||||
constexpr float LittleFloat(float val) {
|
||||
if constexpr (athena::utility::isSystemBigEndian())
|
||||
return athena::utility::swapFloat(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline float BigFloat(float val) {
|
||||
if (!athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swapFloat(val);
|
||||
constexpr float BigFloat(float val) {
|
||||
if constexpr (!athena::utility::isSystemBigEndian())
|
||||
return athena::utility::swapFloat(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline double LittleDouble(double val) {
|
||||
if (athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swapDouble(val);
|
||||
constexpr double LittleDouble(double val) {
|
||||
if constexpr (athena::utility::isSystemBigEndian())
|
||||
return athena::utility::swapDouble(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
inline double BigDouble(double val) {
|
||||
if (!athena::utility::isSystemBigEndian())
|
||||
val = athena::utility::swapDouble(val);
|
||||
constexpr double BigDouble(double val) {
|
||||
if constexpr (!athena::utility::isSystemBigEndian())
|
||||
return athena::utility::swapDouble(val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -175,8 +175,6 @@ atUint64 rand64();
|
|||
std::string join(const std::vector<std::string>& elems, std::string_view delims);
|
||||
void tolower(std::string& str);
|
||||
void toupper(std::string& str);
|
||||
std::string vsprintf(const char* fmt, va_list list);
|
||||
std::string sprintf(const char* fmt, ...);
|
||||
bool parseBool(std::string_view boolean, bool* valid = NULL);
|
||||
|
||||
int countChar(std::string_view str, const char chr, int* lastOccur = NULL);
|
||||
|
|
|
@ -25,12 +25,12 @@ namespace athena {
|
|||
|
||||
static const uint8_t InCo[4] = {0xB, 0xD, 0x9, 0xE}; /* Inverse Coefficients */
|
||||
|
||||
static inline uint32_t pack(const uint8_t* b) {
|
||||
static uint32_t pack(const uint8_t* b) {
|
||||
/* pack bytes into a 32-bit Word */
|
||||
return ((uint32_t)b[3] << 24) | ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | (uint32_t)b[0];
|
||||
}
|
||||
|
||||
static inline void unpack(uint32_t a, uint8_t* b) {
|
||||
static void unpack(uint32_t a, uint8_t* b) {
|
||||
/* unpack bytes from a word */
|
||||
b[0] = (uint8_t)a;
|
||||
b[1] = (uint8_t)(a >> 8);
|
||||
|
@ -38,7 +38,7 @@ static inline void unpack(uint32_t a, uint8_t* b) {
|
|||
b[3] = (uint8_t)(a >> 24);
|
||||
}
|
||||
|
||||
static inline uint8_t xtime(uint8_t a) { return ((a << 1) ^ (((a >> 7) & 1) * 0x11B)); }
|
||||
constexpr uint8_t xtime(uint8_t a) { return ((a << 1) ^ (((a >> 7) & 1) * 0x11B)); }
|
||||
|
||||
static const struct SoftwareAESTables {
|
||||
uint8_t fbsub[256];
|
||||
|
|
|
@ -211,7 +211,7 @@ ALTTPDungeonItemFlags ALTTPFileReader::readDungeonFlags() {
|
|||
flags.HyruleCastle = (flagsByte >> 6) & 1;
|
||||
flags.SewerPassage = (flagsByte >> 7) & 1;
|
||||
|
||||
atDebug("%x %x", flags.flags1, flags.flags2);
|
||||
atDebug("{:x} {:x}", flags.flags1, flags.flags2);
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,8 @@ atInt8 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt8 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "%d", int(val));
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -39,10 +37,8 @@ atUint8 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint8 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "0x%02X", val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("0x{:02X}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -52,10 +48,8 @@ atInt16 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt16 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "%d", int(val));
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -65,10 +59,8 @@ atUint16 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint16 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "0x%04X", val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("0x{:04X}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -78,10 +70,8 @@ atInt32 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt32 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "%d", int(val));
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -91,10 +81,8 @@ atUint32 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint32 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "0x%08X", val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("0x{:08X}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -108,10 +96,8 @@ atInt64 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atInt64 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "%" PRId64, val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -125,10 +111,8 @@ atUint64 NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(atUint64 val) {
|
||||
char str[32];
|
||||
snprintf(str, 32, "0x%016" PRIX64, val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("0x{:016X}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -138,10 +122,8 @@ float NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(float val) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -151,10 +133,8 @@ double NodeToVal(const YAMLNode* node) {
|
|||
}
|
||||
|
||||
std::unique_ptr<YAMLNode> ValToNode(double val) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", val);
|
||||
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
|
||||
ret->m_scalarString = str;
|
||||
ret->m_scalarString = fmt::format(fmt("{}"), val);
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
|
||||
|
@ -189,10 +169,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec2f& val) {
|
|||
ret->m_seqChildren.reserve(2);
|
||||
simd_floats f(val.simd);
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -208,10 +186,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec3f& val) {
|
|||
ret->m_seqChildren.reserve(3);
|
||||
simd_floats f(val.simd);
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -227,10 +203,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec4f& val) {
|
|||
ret->m_seqChildren.reserve(4);
|
||||
simd_floats f(val.simd);
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -246,10 +220,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec2d& val) {
|
|||
ret->m_seqChildren.reserve(2);
|
||||
simd_doubles f(val.simd);
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -265,10 +237,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec3d& val) {
|
|||
ret->m_seqChildren.reserve(3);
|
||||
simd_doubles f(val.simd);
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -284,10 +254,8 @@ std::unique_ptr<YAMLNode> ValToNode(const atVec4d& val) {
|
|||
ret->m_seqChildren.reserve(4);
|
||||
simd_doubles f(val.simd);
|
||||
for (size_t i = 0; i < 4; ++i) {
|
||||
char str[64];
|
||||
snprintf(str, 64, "%f", f[i]);
|
||||
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
|
||||
comp->m_scalarString = str;
|
||||
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
|
||||
ret->m_seqChildren.emplace_back(comp);
|
||||
}
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
|
@ -325,7 +293,7 @@ std::wstring NodeToVal(const YAMLNode* node) {
|
|||
utf8proc_int32_t wc;
|
||||
utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
|
||||
if (len < 0) {
|
||||
atWarning("invalid UTF-8 character while decoding");
|
||||
atWarning(fmt("invalid UTF-8 character while decoding"));
|
||||
return retval;
|
||||
}
|
||||
buf += len;
|
||||
|
@ -341,7 +309,7 @@ std::unique_ptr<YAMLNode> ValToNode(std::wstring_view val) {
|
|||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
|
||||
if (c < 0) {
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
atWarning(fmt("invalid UTF-8 character while encoding"));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
|
||||
|
@ -356,7 +324,7 @@ std::unique_ptr<YAMLNode> ValToNode(std::u16string_view val) {
|
|||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
|
||||
if (c < 0) {
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
atWarning(fmt("invalid UTF-8 character while encoding"));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
|
||||
|
@ -371,7 +339,7 @@ std::unique_ptr<YAMLNode> ValToNode(std::u32string_view val) {
|
|||
utf8proc_uint8_t mb[4];
|
||||
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
|
||||
if (c < 0) {
|
||||
atWarning("invalid UTF-8 character while encoding");
|
||||
atWarning(fmt("invalid UTF-8 character while encoding"));
|
||||
return std::unique_ptr<YAMLNode>(ret);
|
||||
}
|
||||
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
|
||||
|
@ -402,11 +370,11 @@ static const char* ErrorString(yaml_error_type_t errt) {
|
|||
}
|
||||
|
||||
void HandleYAMLParserError(yaml_parser_t* parser) {
|
||||
atError("YAML error: %s: %s", ErrorString(parser->error), parser->problem ? parser->problem : "");
|
||||
atError(fmt("YAML error: {}: {}"), ErrorString(parser->error), parser->problem ? parser->problem : "");
|
||||
}
|
||||
|
||||
void HandleYAMLEmitterError(yaml_emitter_t* emitter) {
|
||||
atError("YAML error: %s: %s", ErrorString(emitter->error), emitter->problem ? emitter->problem : "");
|
||||
atError(fmt("YAML error: {}: {}"), ErrorString(emitter->error), emitter->problem ? emitter->problem : "");
|
||||
}
|
||||
|
||||
int YAMLStdStringReader(YAMLStdStringViewReaderState* reader, unsigned char* buffer, size_t size, size_t* size_read) {
|
||||
|
@ -629,8 +597,8 @@ void YAMLDocWriter::writeU32String(const char* name, std::u32string_view val) {
|
|||
|
||||
void YAMLDocWriter::setStyle(YAMLNodeStyle s) { m_subStack.back()->m_style = s; }
|
||||
|
||||
static inline void InsertNode(std::vector<YAMLNode*>& nodeStack, std::unique_ptr<YAMLNode>& mapKey,
|
||||
std::unique_ptr<YAMLNode>& retVal, std::unique_ptr<YAMLNode>&& newNode) {
|
||||
static void InsertNode(std::vector<YAMLNode*>& nodeStack, std::unique_ptr<YAMLNode>& mapKey,
|
||||
std::unique_ptr<YAMLNode>& retVal, std::unique_ptr<YAMLNode>&& newNode) {
|
||||
if (nodeStack.empty()) {
|
||||
retVal = std::move(newNode);
|
||||
return;
|
||||
|
@ -670,7 +638,7 @@ std::unique_ptr<YAMLNode> YAMLDocReader::ParseEvents(athena::io::IStreamReader*
|
|||
switch (event.type) {
|
||||
case YAML_SCALAR_EVENT: {
|
||||
if (nodeStack.empty()) {
|
||||
atWarning("YAML parser stack empty; skipping scalar node");
|
||||
atWarning(fmt("YAML parser stack empty; skipping scalar node"));
|
||||
break;
|
||||
}
|
||||
std::unique_ptr<YAMLNode> newScalar(new YAMLNode(YAML_SCALAR_NODE));
|
||||
|
@ -805,7 +773,7 @@ YAMLDocReader::RecordRAII YAMLDocReader::enterSubRecord(const char* name) {
|
|||
m_seqTrackerStack.push_back(0);
|
||||
return RecordRAII{this};
|
||||
} else if (!name) {
|
||||
atError("Expected YAML sequence");
|
||||
atError(fmt("Expected YAML sequence"));
|
||||
}
|
||||
for (const auto& item : curSub->m_mapChildren) {
|
||||
if (!item.first.compare(name)) {
|
||||
|
@ -840,7 +808,7 @@ YAMLDocReader::VectorRAII YAMLDocReader::enterSubVector(const char* name, size_t
|
|||
if (nextSub->m_type == YAML_SEQUENCE_NODE) {
|
||||
countOut = nextSub->m_seqChildren.size();
|
||||
} else {
|
||||
atError("'%s' is not a vector field", name);
|
||||
atError(fmt("'{}' is not a vector field"), name);
|
||||
countOut = 0;
|
||||
}
|
||||
m_subStack.push_back(nextSub);
|
||||
|
@ -878,7 +846,7 @@ RETURNTYPE YAMLDocReader::readVal(const char* name) {
|
|||
}
|
||||
}
|
||||
if (name)
|
||||
atWarning("Unable to find field '%s'; returning 0", name);
|
||||
atWarning(fmt("Unable to find field '{}'; returning 0"), name);
|
||||
return RETURNTYPE();
|
||||
}
|
||||
|
||||
|
@ -935,7 +903,7 @@ std::string YAMLDocReader::readString(const char* name) { return readVal<std::st
|
|||
|
||||
std::wstring YAMLDocReader::readWString(const char* name) { return readVal<std::wstring>(name); }
|
||||
|
||||
static inline bool EmitKeyScalar(yaml_emitter_t* doc, const char* val) {
|
||||
static bool EmitKeyScalar(yaml_emitter_t* doc, const char* val) {
|
||||
yaml_event_t event;
|
||||
if (!yaml_scalar_event_initialize(&event, nullptr, nullptr, (yaml_char_t*)val, strlen(val), true, true,
|
||||
YAML_PLAIN_SCALAR_STYLE))
|
||||
|
@ -943,14 +911,14 @@ static inline bool EmitKeyScalar(yaml_emitter_t* doc, const char* val) {
|
|||
return yaml_emitter_emit(doc, &event) != 0;
|
||||
}
|
||||
|
||||
static inline yaml_scalar_style_t ScalarStyle(const YAMLNode& node) {
|
||||
static yaml_scalar_style_t ScalarStyle(const YAMLNode& node) {
|
||||
for (const auto& ch : node.m_scalarString)
|
||||
if (ch == '\n')
|
||||
return YAML_LITERAL_SCALAR_STYLE;
|
||||
return YAML_ANY_SCALAR_STYLE;
|
||||
}
|
||||
|
||||
static inline yaml_sequence_style_t SequenceStyle(const YAMLNode& node) {
|
||||
static yaml_sequence_style_t SequenceStyle(const YAMLNode& node) {
|
||||
if (node.m_style == YAMLNodeStyle::Flow)
|
||||
return YAML_FLOW_SEQUENCE_STYLE;
|
||||
else if (node.m_style == YAMLNodeStyle::Block)
|
||||
|
@ -969,7 +937,7 @@ static inline yaml_sequence_style_t SequenceStyle(const YAMLNode& node) {
|
|||
return (count > 6) ? YAML_BLOCK_SEQUENCE_STYLE : YAML_FLOW_SEQUENCE_STYLE;
|
||||
}
|
||||
|
||||
static inline yaml_mapping_style_t MappingStyle(const YAMLNode& node) {
|
||||
static yaml_mapping_style_t MappingStyle(const YAMLNode& node) {
|
||||
if (node.m_style == YAMLNodeStyle::Flow)
|
||||
return YAML_FLOW_MAPPING_STYLE;
|
||||
else if (node.m_style == YAMLNodeStyle::Block)
|
||||
|
@ -1030,7 +998,7 @@ static const std::string base64_chars =
|
|||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
static inline bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); }
|
||||
inline bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); }
|
||||
|
||||
std::string base64_encode(const atUint8* bytes_to_encode, size_t in_len) {
|
||||
std::string ret;
|
||||
|
|
|
@ -47,7 +47,7 @@ bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data(
|
|||
bool Dir::touch() {
|
||||
srand(time(NULL));
|
||||
atUint64 tmp = utility::rand64();
|
||||
std::string tmpFile = utility::sprintf("%" PRIX64 ".tmp", tmp);
|
||||
std::string tmpFile = fmt::format(fmt("{:016X}.tmp"), tmp);
|
||||
bool ret = FileInfo(m_path + "/" + tmpFile).touch();
|
||||
if (ret)
|
||||
return rm(tmpFile);
|
||||
|
|
|
@ -33,7 +33,7 @@ void FileReader::open() {
|
|||
if (!m_fileHandle) {
|
||||
std::string _filename = filename();
|
||||
if (m_globalErr)
|
||||
atError("File not found '%s'", _filename.c_str());
|
||||
atError(fmt("File not found '{}'"), _filename);
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ void FileReader::open() {
|
|||
void FileReader::close() {
|
||||
if (!m_fileHandle) {
|
||||
if (m_globalErr)
|
||||
atError("Cannot close an unopened stream");
|
||||
atError(fmt("Cannot close an unopened stream"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
|||
}
|
||||
if (m_offset > length()) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to seek in file");
|
||||
atError(fmt("Unable to seek in file"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
|||
}
|
||||
} else if (fseeko64(m_fileHandle, pos, (int)origin) != 0) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to seek in file");
|
||||
atError(fmt("Unable to seek in file"));
|
||||
setError();
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin) {
|
|||
atUint64 FileReader::position() const {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open");
|
||||
atError(fmt("File not open"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ atUint64 FileReader::position() const {
|
|||
atUint64 FileReader::length() const {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open");
|
||||
atError(fmt("File not open"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ atUint64 FileReader::length() const {
|
|||
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open for reading");
|
||||
atError(fmt("File not open for reading"));
|
||||
setError();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void FileReader::open() {
|
|||
m_fileHandle = 0;
|
||||
std::string _filename = filename();
|
||||
if (m_globalErr)
|
||||
atError("File not found '%s'", _filename.c_str());
|
||||
atError("File not found '{}'", _filename);
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ void FileWriter::open(bool overwrite) {
|
|||
|
||||
if (!m_fileHandle) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to open file '%s'", filename().c_str());
|
||||
atError(fmt("Unable to open file '%s'"), filename().c_str());
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ void FileWriter::open(bool overwrite) {
|
|||
void FileWriter::close() {
|
||||
if (!m_fileHandle) {
|
||||
if (m_globalErr)
|
||||
atError("Cannot close an unopened stream");
|
||||
atError(fmt("Cannot close an unopened stream"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -81,14 +81,14 @@ void FileWriter::close() {
|
|||
void FileWriter::seek(atInt64 pos, SeekOrigin origin) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to seek in file, not open");
|
||||
atError(fmt("Unable to seek in file, not open"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fseeko64(m_fileHandle, pos, (int)origin) != 0) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to seek in file");
|
||||
atError(fmt("Unable to seek in file"));
|
||||
setError();
|
||||
}
|
||||
}
|
||||
|
@ -100,14 +100,14 @@ atUint64 FileWriter::length() const { return utility::fileSize(m_filename); }
|
|||
void FileWriter::writeUBytes(const atUint8* data, atUint64 len) {
|
||||
if (!isOpen()) {
|
||||
if (m_globalErr)
|
||||
atError("File not open for writing");
|
||||
atError(fmt("File not open for writing"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fwrite(data, 1, len, m_fileHandle) != len) {
|
||||
if (m_globalErr)
|
||||
atError("Unable to write to stream");
|
||||
atError(fmt("Unable to write to stream"));
|
||||
setError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ void FileWriter::open(bool overwrite) {
|
|||
if (m_fileHandle == INVALID_HANDLE_VALUE) {
|
||||
m_fileHandle = 0;
|
||||
if (m_globalErr)
|
||||
atError("Unable to open file '%s'", filename().c_str());
|
||||
atError("Unable to open file '{}'", filename());
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#include "athena/Global.hpp"
|
||||
#include "athena/Utility.hpp"
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
|
||||
#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:
|
||||
|
@ -37,7 +41,7 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian) {
|
|||
}
|
||||
|
||||
static void __defaultExceptionHandler(athena::error::Level level, const char* file, const char* function, int line,
|
||||
const char* fmt, ...) {
|
||||
fmt::string_view fmt, fmt::format_args args) {
|
||||
std::string levelStr;
|
||||
switch (level) {
|
||||
case athena::error::Level::Warning:
|
||||
|
@ -53,10 +57,7 @@ static void __defaultExceptionHandler(athena::error::Level level, const char* fi
|
|||
break;
|
||||
}
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
std::string msg = athena::utility::vsprintf(fmt, vl);
|
||||
va_end(vl);
|
||||
std::string msg = fmt::internal::vformat(fmt, args);
|
||||
std::cerr << levelStr << " " << file << " " << function << "(" << line << "): " << msg << std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership
|
|||
: m_data(data), m_length(length), m_position(0), m_owns(takeOwnership), m_globalErr(globalErr) {
|
||||
if (!data) {
|
||||
if (m_globalErr)
|
||||
atError("data cannot be NULL");
|
||||
atError(fmt("data cannot be NULL"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ MemoryReader::~MemoryReader() {
|
|||
MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) {
|
||||
if (!data) {
|
||||
if (m_globalErr)
|
||||
atError("data cannot be NULL");
|
||||
atError(fmt("data cannot be NULL"));
|
||||
setError();
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
|
|||
case SeekOrigin::Begin:
|
||||
if ((position < 0 || (atInt64)position > (atInt64)m_length)) {
|
||||
if (m_globalErr)
|
||||
atFatal("Position %0.8X outside stream bounds ", position);
|
||||
atFatal(fmt("Position {:08X} outside stream bounds "), position);
|
||||
m_position = m_length;
|
||||
setError();
|
||||
return;
|
||||
|
@ -60,7 +60,7 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) {
|
|||
case SeekOrigin::Current:
|
||||
if ((((atInt64)m_position + position) < 0 || (m_position + position) > m_length)) {
|
||||
if (m_globalErr)
|
||||
atFatal("Position %0.8X outside stream bounds ", position);
|
||||
atFatal(fmt("Position {:08X} outside stream bounds "), position);
|
||||
m_position = m_length;
|
||||
setError();
|
||||
return;
|
||||
|