Changed folder path and namespace of string_fmt.h and changed includes

dev
anulax1225 ago%!(EXTRA string=1 year)
parent e5207d98b7
commit ab0a14a8a1
  1. 20
      bakara/src/bakara/core/assert.h
  2. 4
      bakara/src/bakara/events/event.h
  3. 14
      bakara/src/bakara/tools/string_fmt.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 <bakara/tools/string_fmt.h>
#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

@ -2,7 +2,7 @@
#include <bakara/core/base.h>
#include <bkpch.h>
#include <bakara/core/string_fmt.h>
#include <bakara/tools/string_fmt.h>
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

@ -1,10 +1,15 @@
#pragma once
/*! \file string_fmt.h
This file provides functions to do string formatting.
*/
#include <bkpch.h>
#include <type_traits>
#include <cctype>
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 <typename... Args>
inline std::string format(const char* fmt, Args... args) {
std::stringstream ss;
Loading…
Cancel
Save