From 803ca9c0bc4509e3be437afa7c3a041e4e9d881a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 12 Dec 2025 21:46:27 +0100 Subject: chore: add the possibility of freestanding headers in `OCL.Core`. Signed-off-by: Amlal El Mahrouss --- include/ocl/detail/config.hpp | 5 +++++ include/ocl/io.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ include/ocl/print.hpp | 9 +++------ include/ocl/smart_socket.hpp | 3 +++ include/ocl/tracked_ptr.hpp | 4 +++- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 include/ocl/io.hpp (limited to 'include') diff --git a/include/ocl/detail/config.hpp b/include/ocl/detail/config.hpp index 3a85618..116c001 100644 --- a/include/ocl/detail/config.hpp +++ b/include/ocl/detail/config.hpp @@ -9,12 +9,15 @@ #define __OCL_CORE_CONFIG #include + +#ifndef __OCL_FREESTANDING #include #include #include #include #include #include +#endif #define OCL_DEPRECATED() [[deprecated]] #define OCL_DEPRECATED_MSG(MSG) [[deprecated(MSG)]] @@ -38,8 +41,10 @@ #endif #ifndef OCL_WINDOWS +#ifndef __OCL_FREESTANDING #include #endif +#endif #if OCL_WANTS_PRAGMA_ONCE #define OCL_HAS_PRAGMA_ONCE 1 diff --git a/include/ocl/io.hpp b/include/ocl/io.hpp new file mode 100644 index 0000000..c7599a5 --- /dev/null +++ b/include/ocl/io.hpp @@ -0,0 +1,40 @@ +/* + * File: print.hpp + * Purpose: OCL Print library + * Author: Amlal El Mahrouss. (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License. Licensed under the BSL 1.0 license + */ + +#ifndef __OCL_CORE_IO +#define __OCL_CORE_IO + +#include + +#ifndef __OCL_FREESTANDING +#define console_io_out std::cout +#define console_io_in std::cin + +#include +#else +#define console_io_out ::ocl::io::null_cout +#define console_io_in ::ocl::io::null_cin + +#warning The OCL doesn't define IO streams in a freestanding host. + +namespace ocl::io +{ + class nullable_stream + { + nullable_stream() = default; + virtual ~nullable_stream() = default; + + nullable_stream& operator<<(...) = delete; + nullable_stream& operator>>(...) = delete; + } + + inline nullable_stream null_cout; + inline nullable_stream null_cin; +} // namespace ocl::io + +#endif +#endif \ No newline at end of file diff --git a/include/ocl/print.hpp b/include/ocl/print.hpp index ea6b483..a667225 100644 --- a/include/ocl/print.hpp +++ b/include/ocl/print.hpp @@ -9,10 +9,7 @@ #define __OCL_CORE_PRINT #include -#include - -#define console_io_out std::cout -#define console_io_in std::cin +#include namespace ocl::io { @@ -24,8 +21,8 @@ namespace ocl::io inline void print() noexcept { - extern void lf() noexcept; - lf(); + extern void lf() noexcept; + lf(); } template diff --git a/include/ocl/smart_socket.hpp b/include/ocl/smart_socket.hpp index 81094fd..ea9c73b 100644 --- a/include/ocl/smart_socket.hpp +++ b/include/ocl/smart_socket.hpp @@ -9,10 +9,13 @@ #define __OCL_SMART_SOCKET #include + +#ifndef __OCL_FREESTANDING #include #ifdef OCL_POSIX # include #endif +#endif // !__OCL_FREESTANDING #endif // __OCL_SMART_SOCKET \ No newline at end of file diff --git a/include/ocl/tracked_ptr.hpp b/include/ocl/tracked_ptr.hpp index 23ced29..03e1644 100644 --- a/include/ocl/tracked_ptr.hpp +++ b/include/ocl/tracked_ptr.hpp @@ -218,9 +218,11 @@ namespace ocl namespace detail { + using tracked_error = std::runtime_error; + inline void throw_tracked_error() { - throw std::runtime_error("tracked_error: memory leak detected."); + throw tracked_error("tracked_error: memory leak detected."); } } // namespace detail -- cgit v1.2.3