diff --git a/bakara/src/bakara/core/assert.h b/bakara/src/bakara/core/assert.h index 8b6b0f7..e222b24 100644 --- a/bakara/src/bakara/core/assert.h +++ b/bakara/src/bakara/core/assert.h @@ -1,22 +1,32 @@ #pragma once +/*! \file assert.h +This file contains the assert macros. CORE macros musn't be used by the application. +*/ + #include "base.h" -#include "string_fmt.h" +#include #ifdef BK_ENABLE_ASSERT - #define BK_CORE_VA_MSG_ASSERT(check, msg, ...) if(!(check)) { BK_CORE_ERROR(Bk::format("Assertion [%s] failed at %s:%d\n\tError : %s", BK_STRINGIFY(check), __FILE__, __LINE__, msg), __VA_ARGS__); BK_DEBUGBREAK(); } + /*! \def BK_CORE_VAMSG_ASSERT(check, msg, ...) + Assertes a condition, and throw an error with the formatted message as description + @param check : Condionne to assert + @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_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_VA_MSG_ASSERT(check, msg, ...) if(!(check)) { BK_ERROR(Bk::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::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 - #define BK_CORE_VA_MSG_ASSERT(check, msg, ...) + #define BK_CORE_VAMSG_ASSERT(check, msg, ...) #define BK_CORE_MSG_ASSERT(check, msg) #define BK_CORE_ASSERT(check) - #define BK_VA_MSG_ASSERT(check, msg, ...) + #define BK_VAMSG_ASSERT(check, msg, ...) #define BK_MSG_ASSERT(check, msg) #define BK_ASSERT(check) #endif \ No newline at end of file diff --git a/bakara/src/bakara/events/event.h b/bakara/src/bakara/events/event.h index 0d8c251..e8dc84a 100644 --- a/bakara/src/bakara/events/event.h +++ b/bakara/src/bakara/events/event.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace Bk { enum class EventType @@ -42,7 +42,7 @@ namespace Bk { #define EVENT_CLASS_CATEGORY(category) virtual int get_category_flags() const override { return category; } #ifdef BK_DEBUG - #define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return format(str, __VA_ARGS__); } + #define EVENT_STRINGIFY(str, ...) std::string to_string() const override { return Tools::format(str, __VA_ARGS__); } #define GET_EVENT_STRING(event) event.to_string() #else diff --git a/bakara/src/bakara/core/string_fmt.h b/bakara/src/bakara/tools/string_fmt.h similarity index 84% rename from bakara/src/bakara/core/string_fmt.h rename to bakara/src/bakara/tools/string_fmt.h index d7e3cc6..4eb14d1 100644 --- a/bakara/src/bakara/core/string_fmt.h +++ b/bakara/src/bakara/tools/string_fmt.h @@ -1,10 +1,15 @@ #pragma once +/*! \file string_fmt.h +This file provides functions to do string formatting. +*/ + #include #include #include -namespace Bk { +namespace Bk::Tools { + inline void format_impl(std::stringstream& ss, const char* format) { while (*format) { if (*format == '%' && *++format != '%') // %% == % (not a format directive) @@ -44,7 +49,12 @@ namespace Bk { } // the format string is exhausted and we still have args : throw throw std::invalid_argument("Too many arguments\n"); } - + /*! \fn std::string Bk::Tools::format(const char* fmt, Args... args) + Formats a string, printf like. Accepts integers, floating point numbers, strings, booléen. + @param fmt : string to format + @param args : variable arguments to put in the string + @return String formatted + */ template inline std::string format(const char* fmt, Args... args) { std::stringstream ss;