diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-12-18 14:00:03 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-12-18 14:00:03 +0100 |
| commit | 8042003647b50e9fddfe500677a132130449d69e (patch) | |
| tree | 82e89f225b8324c91a84d61008c790136d681b5a /kapi | |
| parent | 0c8e77b367ca617beb2c30cd7e032cd9b24aeea4 (diff) | |
| download | teachos-8042003647b50e9fddfe500677a132130449d69e.tar.xz teachos-8042003647b50e9fddfe500677a132130449d69e.zip | |
kapi/cio: implement formatted printing
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/include/kapi/cio.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/kapi/include/kapi/cio.hpp b/kapi/include/kapi/cio.hpp index 071e6cb..98c715b 100644 --- a/kapi/include/kapi/cio.hpp +++ b/kapi/include/kapi/cio.hpp @@ -3,8 +3,12 @@ #include "kapi/cio/output_device.hpp" // IWYU pragma: export +#include <kstd/format> + +#include <array> #include <optional> #include <string_view> +#include <type_traits> namespace teachos::cio { @@ -46,6 +50,57 @@ namespace teachos::cio //! //! @param text The error text to print. auto println_error(std::string_view text) -> void; + + template<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + auto vprint(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher<std::remove_cvref_t<Args>>} + ... + }; + vprint(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + template<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + auto vprint(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher<std::remove_cvref_t<Args>>} + ... + }; + vprint(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + println(""); + } + + template<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print_error(kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + auto vprint_error(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher<std::remove_cvref_t<Args>>} + ... + }; + vprint_error(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + template<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println_error(kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + auto vprint_error(std::string_view format, kstd::format_args args) -> void; + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher<std::remove_cvref_t<Args>>} + ... + }; + vprint_error(format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + println_error(""); + } + } // namespace teachos::cio #endif |
