diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-12 21:46:27 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-12 21:48:59 +0100 |
| commit | 803ca9c0bc4509e3be437afa7c3a041e4e9d881a (patch) | |
| tree | 776902d76b963726c818af82c431ab332dea6b10 | |
| parent | c3dab4299a7f70b2b69e461de9ab03957653fcce (diff) | |
chore: add the possibility of freestanding headers in `OCL.Core`.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | include/ocl/detail/config.hpp | 5 | ||||
| -rw-r--r-- | include/ocl/io.hpp | 40 | ||||
| -rw-r--r-- | include/ocl/print.hpp | 9 | ||||
| -rw-r--r-- | include/ocl/smart_socket.hpp | 3 | ||||
| -rw-r--r-- | include/ocl/tracked_ptr.hpp | 4 |
6 files changed, 60 insertions, 7 deletions
@@ -13,4 +13,10 @@ The OCL requires the following: - [CMake](https://cmake.org/) - [Git](https://git-scm.com/) +## Freestanding Status + +The Freestanding Status is a concept where a module is evaluated on whether it has or is fully freestanding or not. + +- Half-Verified ({option, is_same}.hpp) + ##### (c) 2025 Amlal El Mahrouss and OCL Authors, licensed under the Boost Software License. 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 <boost/config.hpp> + +#ifndef __OCL_FREESTANDING #include <boost/core/addressof.hpp> #include <boost/core/nvp.hpp> #include <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> #include <boost/container/allocator.hpp> #include <boost/assert.hpp> +#endif #define OCL_DEPRECATED() [[deprecated]] #define OCL_DEPRECATED_MSG(MSG) [[deprecated(MSG)]] @@ -38,8 +41,10 @@ #endif #ifndef OCL_WINDOWS +#ifndef __OCL_FREESTANDING #include <unistd.h> #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 <ocl/detail/config.hpp> + +#ifndef __OCL_FREESTANDING +#define console_io_out std::cout +#define console_io_in std::cin + +#include <iostream> +#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 <ocl/detail/config.hpp> -#include <iostream> - -#define console_io_out std::cout -#define console_io_in std::cin +#include <ocl/io.hpp> 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 <typename... Args> 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 <ocl/detail/config.hpp> + +#ifndef __OCL_FREESTANDING #include <boost/asio.hpp> #ifdef OCL_POSIX # include <ocl/posix/unique_socket.hpp> #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 |
