From 603f89baa6a4bc4fd561fc1992a90ef88f0a8c82 Mon Sep 17 00:00:00 2001 From: anulax1225 Date: Thu, 17 Oct 2024 18:04:43 +0200 Subject: [PATCH] Next step --- src/bakatools/container/data_stream.h | 3 +++ src/bakatools/file_system/dir_entry.cpp | 2 +- src/bakatools/file_system/dir_entry.h | 3 ++- src/bakatools/file_system/file.cpp | 3 ++- src/bakatools/file_system/file.h | 2 +- src/bakatools/logging/assert.h | 10 +++++----- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bakatools/container/data_stream.h b/src/bakatools/container/data_stream.h index 24a28c4..5172dfd 100644 --- a/src/bakatools/container/data_stream.h +++ b/src/bakatools/container/data_stream.h @@ -2,6 +2,7 @@ #include #include +#include namespace Bk::Type { class DataStream @@ -13,6 +14,8 @@ namespace Bk::Type { DataStream(std::vector data) : payload(data) {} + operator std::string() { return std::string(payload.data(), payload.size()); } + int size() { return payload.size(); } void reverse() { std::reverse(payload.begin(), payload.end()); } diff --git a/src/bakatools/file_system/dir_entry.cpp b/src/bakatools/file_system/dir_entry.cpp index c80ad1c..ab43a85 100644 --- a/src/bakatools/file_system/dir_entry.cpp +++ b/src/bakatools/file_system/dir_entry.cpp @@ -24,7 +24,7 @@ namespace Bk return ent.path().filename().string(); } - uintmax_t DirEntry::size() + u64 DirEntry::size() { return ent.file_size(); } diff --git a/src/bakatools/file_system/dir_entry.h b/src/bakatools/file_system/dir_entry.h index c8d7816..dc4a211 100644 --- a/src/bakatools/file_system/dir_entry.h +++ b/src/bakatools/file_system/dir_entry.h @@ -1,6 +1,7 @@ #pragma once #include +#include "bakatools/container/types.h" #include #include @@ -33,7 +34,7 @@ namespace Bk std::string relative_path(); std::string name(); - uintmax_t size(); + u64 size(); std::chrono::time_point last_write(); bool exists(); FilePerms perms(); diff --git a/src/bakatools/file_system/file.cpp b/src/bakatools/file_system/file.cpp index 51d476b..4e87f64 100644 --- a/src/bakatools/file_system/file.cpp +++ b/src/bakatools/file_system/file.cpp @@ -11,8 +11,9 @@ namespace Bk { if (exists()) std::filesystem::copy_file(ent.path(), path, opt); } - Type::DataStream File::read(int size) + Type::DataStream File::read(u64 size) { + size = size ? size : this->size(); std::vector data; if(exists()) { diff --git a/src/bakatools/file_system/file.h b/src/bakatools/file_system/file.h index 178304a..ba49af1 100644 --- a/src/bakatools/file_system/file.h +++ b/src/bakatools/file_system/file.h @@ -20,7 +20,7 @@ namespace Bk { int remove(); void copy(std::string path, CopyOption opt = CopyOption::overwrite_existing) override; - Type::DataStream read(int size); + Type::DataStream read(u64 size = 0); bool write(Type::DataStream stream); BK_DIR_ENTRY_TYPE(regular) diff --git a/src/bakatools/logging/assert.h b/src/bakatools/logging/assert.h index bb02b21..94a3e98 100644 --- a/src/bakatools/logging/assert.h +++ b/src/bakatools/logging/assert.h @@ -5,16 +5,16 @@ This file contains the assert macros. CORE macros musn't be used by the applicat */ #include "log.h" -#include +#include "bakatools/string/format.h" #define BK_STATIC_DEBUGBREAK() exit(1) -#define BK_STATIC_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_STATIC_CORE_ERROR(Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_STATIC_DEBUGBREAK(); } +#define BK_STATIC_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_STATIC_CORE_ERROR(Tools::string_format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_STATIC_DEBUGBREAK(); } #define BK_STATIC_CORE_MSG_ASSERT(check, msg) if(!(check)) { BK_STATIC_CORE_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_STATIC_DEBUGBREAK(); } #define BK_STATIC_CORE_ASSERT(check) if(!(check)) { BK_STATIC_CORE_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_STATIC_DEBUGBREAK(); } -#define BK_STATIC_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_STATIC_ERROR(Bk::Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_STATIC_DEBUGBREAK(); } +#define BK_STATIC_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_STATIC_ERROR(Bk::Tools::string_format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_STATIC_DEBUGBREAK(); } #define BK_STATIC_MSG_ASSERT(check, msg) if(!(check)) { BK_STATIC_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_STATIC_DEBUGBREAK(); } #define BK_STATIC_ASSERT(check) if(!(check)) { BK_STATIC_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_STATIC_DEBUGBREAK(); } @@ -33,11 +33,11 @@ This file contains the assert macros. CORE macros musn't be used by the applicat @param msg : format string error message @param ... : variable arguments to put in the string */ - #define BK_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_CORE_ERROR(Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } + #define BK_CORE_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_CORE_ERROR(Tools::string_format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } #define BK_CORE_MSG_ASSERT(check, msg) if(!(check)) { BK_CORE_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_DEBUGBREAK(); } #define BK_CORE_ASSERT(check) if(!(check)) { BK_CORE_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_DEBUGBREAK(); } - #define BK_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_ERROR(Bk::Tools::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } + #define BK_VAMSG_ASSERT(check, msg, ...) if(!(check)) { BK_ERROR(Bk::Tools::string_format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } #define BK_MSG_ASSERT(check, msg) if(!(check)) { BK_ERROR("Assertion [{0}] failed at {1}:{2}\n\tError : {3}", BK_STRINGIFY(check), __FILE__, __LINE__, msg); BK_DEBUGBREAK(); } #define BK_ASSERT(check) if(!(check)) { BK_ERROR("Assertion [{0}] failed at {1}:{2}", BK_STRINGIFY(check), __FILE__, __LINE__); BK_DEBUGBREAK(); } #else