From de96b0588ab680e1002c12df7ea7900d7eb71cf8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 19 Dec 2025 11:46:46 +0100 Subject: kstd: move println to kstd --- libs/kstd/include/kstd/print | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 libs/kstd/include/kstd/print (limited to 'libs') diff --git a/libs/kstd/include/kstd/print b/libs/kstd/include/kstd/print new file mode 100644 index 0000000..df42997 --- /dev/null +++ b/libs/kstd/include/kstd/print @@ -0,0 +1,86 @@ +#ifndef KSTD_PRINT +#define KSTD_PRINT + +#include + +#include +#include +#include + +namespace kstd +{ + + enum struct print_sink + { + stdout, + stderr, + }; + + namespace os + { + auto vprint(print_sink sink, std::string_view format, kstd::format_args args) -> void; + } // namespace os + + //! @qualifier kernel-defined + //! Format the given string using the given arguments and print it to the currently active output device. + //! + //! @param format The format string + //! @param args The arguments to use to place in the format string's placeholders. + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(kstd::format_string...> format, Args &&... args) -> void + { + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + os::vprint(print_sink::stdout, format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + //! @qualifier kernel-defined + //! Format the given error string using the given arguments and print it to the currently active output device. + //! + //! @param format The format string + //! @param args The arguments to use to place in the format string's placeholders. + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(print_sink sink, kstd::format_string...> format, Args &&... args) -> void + { + auto arguments = std::array{ + kstd::format_arg{&args, kstd::format_dispatcher>} + ... + }; + os::vprint(sink, format.str, kstd::format_args{arguments.data(), sizeof...(Args)}); + } + + //! @qualifier kernel-defined + //! Format the given string using the given arguments and print it, including a newline, to the currently active + //! output device. + //! + //! @param format The format string + //! @param args The arguments to use to place in the format string's placeholders. + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(kstd::format_string...> format, Args &&... args) -> void + { + print(format, std::forward(args)...); + print(print_sink::stdout, "\n"); + } + + //! @qualifier kernel-defined + //! Format the given error string using the given arguments and print it, including a newline, to the currently active + //! output device. + //! + //! @param format The format string + //! @param args The arguments + template + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(print_sink sink, kstd::format_string...> format, Args &&... args) -> void + { + print(sink, format, std::forward(args)...); + print(sink, "\n"); + } + +} // namespace kstd + +#endif \ No newline at end of file -- cgit v1.2.3