From bba582964bded940f9dc280fd15ed84aa2db2d39 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 17 Sep 2025 09:59:28 +0200 Subject: feat! lib: reorganize library (OCL v1.0.44) Signed-off-by: Amlal El Mahrouss --- dev/lib/memory/allocator_system.hpp | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 dev/lib/memory/allocator_system.hpp (limited to 'dev/lib/memory') diff --git a/dev/lib/memory/allocator_system.hpp b/dev/lib/memory/allocator_system.hpp new file mode 100644 index 0000000..1243ed5 --- /dev/null +++ b/dev/lib/memory/allocator_system.hpp @@ -0,0 +1,75 @@ +/* + * File: core/allocator_system.hpp + * Purpose: Allocator System container. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss. Licensed under the BSL 1.0 license + */ + +#ifndef _OCL_ALLOCATOR_SYSTEM_HPP +#define _OCL_ALLOCATOR_SYSTEM_HPP + +#include +#include +#include + +namespace ocl +{ + template + struct new_op final + { + inline auto operator()() -> type* + { + return new type; + } + + template + inline auto var_alloc(var_type... args) -> type* + { + return new type{args...}; + } + }; + + template + struct delete_op final + { + inline auto operator()(type* t) -> void + { + delete t; + } + }; + + template + class allocator_system + { + allocator_new alloc_; + allocator_delete del_; + + public: + allocator_system() = default; + ~allocator_system() = default; + + allocator_system& operator=(const allocator_system&) = delete; + allocator_system(const allocator_system&) = delete; + + ret_type* claim() noexcept + { + return alloc_(); + } + + template + auto construct(var_type... args) -> std::shared_ptr + { + return std::shared_ptr(alloc_.template var_alloc(args...), allocator_delete{}); + } + + void unclaim(ret_type* ptr) + { + del_(ptr); + } + }; + + template + using standard_allocator_type = allocator_system, delete_op>; +} // namespace ocl + +#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP -- cgit v1.2.3