From f011d871ef3af26c8f4e19de2c8d781c601ceffb Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Fri, 11 Oct 2024 00:32:49 +0200 Subject: Add console printing --- asl/format.hpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'asl/format.hpp') diff --git a/asl/format.hpp b/asl/format.hpp index f17329f..b4cb439 100644 --- a/asl/format.hpp +++ b/asl/format.hpp @@ -2,23 +2,11 @@ #include "asl/integers.hpp" #include "asl/meta.hpp" -#include "asl/utility.hpp" +#include "asl/io.hpp" namespace asl { -// @Todo Move this to io -class writer -{ -public: - writer() = default; - ASL_DELETE_COPY_MOVE(writer); - virtual ~writer() = default; - - // @Todo Use string view, or span of bytes? - virtual void write(const char* str, int64_t len) = 0; -}; - class formatter; template @@ -70,21 +58,21 @@ public: }; // @Todo Use string_view -template +template void format(writer* w, const char* fmt, const Args&... args) { - format_internals::type_erased_arg type_erased_args[] = { - format_internals::type_erased_arg(args)... - }; - - // @Todo Use array extent - format_internals::format(w, fmt, type_erased_args, types_count); -} + if constexpr (types_count > 0) + { + format_internals::type_erased_arg type_erased_args[] = { + format_internals::type_erased_arg(args)... + }; -// @Todo Use string_view -inline void format(writer* w, const char* fmt) -{ - format_internals::format(w, fmt, nullptr, 0); + format_internals::format(w, fmt, type_erased_args, types_count); + } + else + { + format_internals::format(w, fmt, nullptr, 0); + } } template @@ -96,6 +84,8 @@ void AslFormat(formatter& f, const char (&str)[N]) void AslFormat(formatter& f, float); void AslFormat(formatter& f, double); +void AslFormat(formatter& f, bool); + void AslFormat(formatter& f, uint8_t); void AslFormat(formatter& f, uint16_t); void AslFormat(formatter& f, uint32_t); -- cgit