|
|
|
|
@@ -1,5 +1,7 @@
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <BAN/Move.h>
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
@@ -12,16 +14,19 @@ namespace BAN::Formatter
|
|
|
|
|
static void print(F putc, const char* format);
|
|
|
|
|
|
|
|
|
|
template<typename F, typename Arg, typename... Args>
|
|
|
|
|
static void print(F putc, const char* format, const Arg& arg, const Args&... args);
|
|
|
|
|
static void print(F putc, const char* format, Arg&& arg, Args&&... args);
|
|
|
|
|
|
|
|
|
|
template<typename F, typename... Args>
|
|
|
|
|
static void println(F putc, const char* format = "", const Args&... args);
|
|
|
|
|
static void println(F putc, const char* format, Args&&... args);
|
|
|
|
|
|
|
|
|
|
template<typename F, typename T>
|
|
|
|
|
static size_t print_argument(F putc, const char* format, const T& arg);
|
|
|
|
|
static void print_argument(F putc, T value, const ValueFormat& format);
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
|
{
|
|
|
|
|
template<typename F, typename T>
|
|
|
|
|
static void print_argument_impl(F putc, T value, const ValueFormat& format);
|
|
|
|
|
static size_t parse_format_and_print_argument(F putc, const char* format, T&& arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -49,7 +54,7 @@ namespace BAN::Formatter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename F, typename Arg, typename... Args>
|
|
|
|
|
void print(F putc, const char* format, const Arg& arg, const Args&... args)
|
|
|
|
|
void print(F putc, const char* format, Arg&& arg, Args&&... args)
|
|
|
|
|
{
|
|
|
|
|
while (*format && *format != '{')
|
|
|
|
|
{
|
|
|
|
|
@@ -59,22 +64,25 @@ namespace BAN::Formatter
|
|
|
|
|
|
|
|
|
|
if (*format == '{')
|
|
|
|
|
{
|
|
|
|
|
size_t arg_len = print_argument(putc, format, arg);
|
|
|
|
|
size_t arg_len = detail::parse_format_and_print_argument(putc, format, forward<Arg>(arg));
|
|
|
|
|
if (arg_len == size_t(-1))
|
|
|
|
|
return print(putc, format);
|
|
|
|
|
print(putc, format + arg_len, args...);
|
|
|
|
|
print(putc, format + arg_len, forward<Args>(args)...);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename F, typename... Args>
|
|
|
|
|
void println(F putc, const char* format, const Args&... args)
|
|
|
|
|
void println(F putc, const char* format, Args&&... args)
|
|
|
|
|
{
|
|
|
|
|
print(putc, format, args...);
|
|
|
|
|
putc('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
template<typename F, typename Arg>
|
|
|
|
|
size_t print_argument(F putc, const char* format, const Arg& argument)
|
|
|
|
|
size_t parse_format_and_print_argument(F putc, const char* format, Arg&& argument)
|
|
|
|
|
{
|
|
|
|
|
ValueFormat value_format;
|
|
|
|
|
|
|
|
|
|
@@ -131,7 +139,7 @@ namespace BAN::Formatter
|
|
|
|
|
if (format[i] != '}')
|
|
|
|
|
return size_t(-1);
|
|
|
|
|
|
|
|
|
|
print_argument_impl(putc, argument, value_format);
|
|
|
|
|
print_argument(putc, forward<Arg>(argument), value_format);
|
|
|
|
|
|
|
|
|
|
return i + 1;
|
|
|
|
|
}
|
|
|
|
|
@@ -221,33 +229,24 @@ namespace BAN::Formatter
|
|
|
|
|
putc(value_to_base_char((value >> i) & 0xF, 16, format.upper));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
TEMPLATE SPECIALIZATIONS
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, short value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, int value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, long value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, long long value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F, integral T> void print_argument(F putc, T value, const ValueFormat& format) { detail::print_integer(putc, value, format); }
|
|
|
|
|
template<typename F, floating_point T> void print_argument(F putc, T value, const ValueFormat& format) { detail::print_floating(putc, value, format); }
|
|
|
|
|
template<typename F, pointer T> void print_argument(F putc, T value, const ValueFormat& format) { detail::print_pointer(putc, (void*)value, format); }
|
|
|
|
|
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, unsigned short value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, unsigned int value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, unsigned long value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, unsigned long long value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument(F putc, char value, const ValueFormat&) { putc(value); }
|
|
|
|
|
template<typename F> void print_argument(F putc, bool value, const ValueFormat&) { print(putc, value ? "true" : "false"); }
|
|
|
|
|
template<typename F> void print_argument(F putc, const char* value, const ValueFormat&) { print(putc, value);}
|
|
|
|
|
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, float value, const ValueFormat& format) { print_floating(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, double value, const ValueFormat& format) { print_floating(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, long double value, const ValueFormat& format) { print_floating(putc, value, format); }
|
|
|
|
|
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, char value, const ValueFormat&) { putc(value); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, signed char value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, unsigned char value, const ValueFormat& format) { print_integer(putc, value, format); }
|
|
|
|
|
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, bool value, const ValueFormat& format) { print(putc, value ? "true" : "false"); }
|
|
|
|
|
|
|
|
|
|
template<typename F, typename T> void print_argument_impl(F putc, T* value, const ValueFormat& format) { print_pointer(putc, (void*)value, format); }
|
|
|
|
|
template<typename F> void print_argument_impl(F putc, const char* value, const ValueFormat&) { print(putc, value);}
|
|
|
|
|
//template<typename F> void print_argument(F putc, signed char value, const ValueFormat& format) { detail::print_integer(putc, value, format); }
|
|
|
|
|
//template<typename F> void print_argument(F putc, unsigned char value, const ValueFormat& format) { detail::print_integer(putc, value, format); }
|
|
|
|
|
//template<typename F, typename T> void print_argument(F putc, T* value, const ValueFormat& format) { detail::print_pointer(putc, (void*)value, format); }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|