From f7840112f468367feb9aee8cbc9146d74a1e87e0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 8 Dec 2025 03:34:18 -0500 Subject: chore: new smart_ptr helpers, tracked_ptr using header guards, and option chores. Signed-off-by: Amlal El Mahrouss --- examples/.keep | 0 include/ocl/option.hpp | 5 ++--- include/ocl/smart_ptr.hpp | 19 ++++++++++++++----- include/ocl/tracked_ptr.hpp | 5 ++++- 4 files changed, 20 insertions(+), 9 deletions(-) delete mode 100644 examples/.keep diff --git a/examples/.keep b/examples/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/include/ocl/option.hpp b/include/ocl/option.hpp index e114b43..9286ef9 100644 --- a/include/ocl/option.hpp +++ b/include/ocl/option.hpp @@ -12,7 +12,7 @@ namespace ocl { - enum class return_type + enum struct return_type { invalid = 0, okay = 100, @@ -50,8 +50,7 @@ namespace ocl { if (ret_ == return_type::err) { - ErrorHandler err_handler; - err_handler(input ? input : "option::error"); + ErrorHandler{}(input ? input : "option::error"); } return *this; diff --git a/include/ocl/smart_ptr.hpp b/include/ocl/smart_ptr.hpp index adab5aa..f8b7108 100644 --- a/include/ocl/smart_ptr.hpp +++ b/include/ocl/smart_ptr.hpp @@ -1,13 +1,14 @@ /* - * File: unique_pr.hpp - * Purpose: Unique Pointer helpers. + * File: smart_ptr.hpp + * Purpose: Smart Pointer helpers. * 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_UNIQUE_PTR -#define __OCL_UNIQUE_PTR +#ifndef __OCL_SMART_PTR +#define __OCL_SMART_PTR +#include #include #include #include @@ -16,6 +17,14 @@ namespace ocl { template using unique_ptr = std::unique_ptr; + + template + inline auto delete_ptr(T& obj) -> auto { return std::shared_ptr{obj, _Deleter()}; } + + /// @brief Constructs a `null_ptr`, that is, a pointer that isn't deleted from the heap. + template + inline auto null_deleter(T& obj) -> auto { return delete_ptr(obj); } + } -#endif // ifndef __OCL_UNIQUE_PTR \ No newline at end of file +#endif // ifndef __OCL_SMART_PTR \ No newline at end of file diff --git a/include/ocl/tracked_ptr.hpp b/include/ocl/tracked_ptr.hpp index 5a1b94e..23ced29 100644 --- a/include/ocl/tracked_ptr.hpp +++ b/include/ocl/tracked_ptr.hpp @@ -5,7 +5,8 @@ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. */ -#pragma once +#ifndef __OCL_TRACKED_PTR +#define __OCL_TRACKED_PTR #include #include @@ -233,3 +234,5 @@ namespace ocl } } } // namespace ocl + +#endif // ifndef __OCL_TRACKED_PTR \ No newline at end of file -- cgit v1.2.3