diff options
Diffstat (limited to 'libs/kstd/kstd/print')
| -rw-r--r-- | libs/kstd/kstd/print | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libs/kstd/kstd/print b/libs/kstd/kstd/print new file mode 100644 index 0000000..1033f72 --- /dev/null +++ b/libs/kstd/kstd/print @@ -0,0 +1,69 @@ +#ifndef KSTD_PRINT +#define KSTD_PRINT + +#include <kstd/bits/print_sink.hpp> // IWYU pragma: export +#include <kstd/format> +#include <kstd/os/print.hpp> + +#include <type_traits> + +namespace kstd +{ + + //! @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<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(kstd::format_string<std::type_identity_t<Args>...> format, Args const &... args) -> void + { + auto const arg_store = kstd::make_format_args(args...); + os::vprint(print_sink::stdout, format.str_view, arg_store.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<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto print(print_sink sink, kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + auto const arg_store = kstd::make_format_args(args...); + os::vprint(sink, format.str_view, arg_store.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<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + print(print_sink::stdout, format, std::forward<Args>(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<typename... Args> + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + auto println(print_sink sink, kstd::format_string<std::type_identity_t<Args>...> format, Args &&... args) -> void + { + print(sink, format, std::forward<Args>(args)...); + print(sink, "\n"); + } + +} // namespace kstd + +#endif
\ No newline at end of file |
