summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-08 03:34:18 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-08 03:34:44 -0500
commitf7840112f468367feb9aee8cbc9146d74a1e87e0 (patch)
tree4a39a14b3c7dba391820c6d381226ede5cd2a2ac /include
parent2eddcbe7082ac3f17478d08d42976b09ddf23492 (diff)
chore: new smart_ptr helpers, tracked_ptr using header guards, and option chores.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/ocl/option.hpp5
-rw-r--r--include/ocl/smart_ptr.hpp19
-rw-r--r--include/ocl/tracked_ptr.hpp5
3 files changed, 20 insertions, 9 deletions
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 <boost/core/null_deleter.hpp>
#include <ocl/detail/config.hpp>
#include <ocl/tracked_ptr.hpp>
#include <memory>
@@ -16,6 +17,14 @@ namespace ocl
{
template <class T, class Del>
using unique_ptr = std::unique_ptr<T, Del>;
+
+ template<class T, class _Deleter>
+ inline auto delete_ptr(T& obj) -> auto { return std::shared_ptr<T>{obj, _Deleter()}; }
+
+ /// @brief Constructs a `null_ptr`, that is, a pointer that isn't deleted from the heap.
+ template<class T>
+ inline auto null_deleter(T& obj) -> auto { return delete_ptr<T, boost::null_deleter>(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 <exception>
#include <ocl/detail/config.hpp>
@@ -233,3 +234,5 @@ namespace ocl
}
}
} // namespace ocl
+
+#endif // ifndef __OCL_TRACKED_PTR \ No newline at end of file