summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/print.hpp
blob: 0d9d0fc40b97580a1b20be75b9b6a9322a32c744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// Official repository: https://github.com/ocl-org/core

#ifndef OCL_CORE_PRINT
#define OCL_CORE_PRINT

#include <ocl/detail/config.hpp>
#include <ocl/io.hpp>

namespace ocl::io
{

	template <typename T>
	inline void print(T fmt) noexcept
	{
		console_io_out << fmt;
	}

	inline void print() noexcept
	{
		extern void lf() noexcept;
		lf();
	}

	template <typename... Args>
	inline void print(Args... fmt) noexcept
	{
		print(fmt...);
		print();
	}

	template <typename T, typename... Args>
	inline void print(T fmt, Args... other) noexcept
	{
		console_io_out << fmt;
		print(other...);
	}

	namespace detail
	{
		inline bool is_stdio_sync = true;

		using io_error = std::runtime_error;

		inline void throw_option_invalid_type_error(const boost::source_location& loc = BOOST_CURRENT_LOCATION)
		{
			throw io_error(loc.to_string());
		}
	} // namespace detail

	inline void enable_stdio_sync(const bool& enable) noexcept
	{
		detail::is_stdio_sync = enable;
		console_io_out.sync_with_stdio(detail::is_stdio_sync);
	}

	inline const bool& is_stdio_sync()
	{
		return detail::is_stdio_sync;
	}

	inline void lf() noexcept
	{
#ifdef OCL_USE_CRLF_ENDINGS
		if (!is_stdio_sync)
			print("\r\n");
#else
		if (!is_stdio_sync())
			print("\n");
#endif

		if (is_stdio_sync())
			console_io_out << std::endl;
	}

	template <typename... T>
	inline void println(T... fmt) noexcept
	{
		print(fmt...);
		lf();
	}

} // namespace ocl::io

#endif // ifndef OCL_CORE_PRINT