From f8f05ded6a1da18052a6154393710d55ff6ce8bd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 30 Nov 2025 07:09:34 -0500 Subject: chore: new improvements over the previous impelemntations of allocator_op. Signed-off-by: Amlal El Mahrouss --- include/ocl/core/allocator_op.hpp | 26 +++----- include/ocl/core/chunk_string.hpp | 122 -------------------------------------- include/ocl/core/handler.hpp | 42 ------------- 3 files changed, 9 insertions(+), 181 deletions(-) delete mode 100644 include/ocl/core/chunk_string.hpp delete mode 100644 include/ocl/core/handler.hpp (limited to 'include') diff --git a/include/ocl/core/allocator_op.hpp b/include/ocl/core/allocator_op.hpp index c086901..539c7e6 100644 --- a/include/ocl/core/allocator_op.hpp +++ b/include/ocl/core/allocator_op.hpp @@ -13,8 +13,9 @@ namespace ocl { + /// @note these are guidelines on allocating a resource template - struct new_op final + struct global_new_op final { inline auto operator()() -> type* { @@ -22,14 +23,15 @@ namespace ocl } template - inline auto var_alloc(var_type... args) -> type* + inline auto var_alloc(var_type&&... args) -> type* { - return new type{args...}; + return new type{std::forward(args)...}; } }; + /// @note these are guidelines on deleting a resource template - struct delete_op final + struct global_delete_op final { inline auto operator()(type* t) -> void { @@ -50,25 +52,15 @@ namespace ocl allocator_op& operator=(const allocator_op&) = delete; allocator_op(const allocator_op&) = delete; - ret_type* claim() - { - return alloc_op_(); - } - template - auto construct(var_type... args) -> std::shared_ptr - { - return std::shared_ptr(alloc_op_.template var_alloc(args...), allocator_delete{}); - } - - void unclaim(ret_type* ptr) + auto construct(var_type&&... args) -> std::shared_ptr { - free_op_(ptr); + return std::shared_ptr(alloc_op_.template var_alloc(args...), free_op_); } }; template - using allocator_type = allocator_op, delete_op>; + using allocator_type = allocator_op, global_delete_op>; } // namespace ocl #endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP \ No newline at end of file diff --git a/include/ocl/core/chunk_string.hpp b/include/ocl/core/chunk_string.hpp deleted file mode 100644 index a2380f6..0000000 --- a/include/ocl/core/chunk_string.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * File: core/chunk_string.hpp - * Purpose: Chunked String implementation for the OCL C++ library. - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss - */ - -#ifndef OCL_UTILITY_CHUNK_STRING_HPP -#define OCL_UTILITY_CHUNK_STRING_HPP - -#include -#include -#include - -namespace ocl -{ - template - class basic_chunk_string; - - template - class basic_chunk_string final - { - public: - using condition_type = bool; - - private: - char_type chunk_[max_chunk_size] = {0}; - std::size_t chunk_total_{}; - - condition_type bad_{false}; - - public: - const condition_type& bad{bad_}; - - basic_chunk_string() = default; - - basic_chunk_string(const char_type* in) - { - this->operator+=(in); - } - - basic_chunk_string(const std::basic_string& in) - { - this->operator+=(in); - } - - ~basic_chunk_string() = default; - - basic_chunk_string& operator=(const basic_chunk_string&) = delete; - basic_chunk_string(const basic_chunk_string&) = delete; - - public: - /// @brief Append a std::basic_string to the chunk string. - basic_chunk_string& operator+=(const char_type* in) - { - if (in == nullptr || bad_) - return *this; - - this->operator+=(std::basic_string(in)); - - return *this; - } - - basic_chunk_string& operator+=(const std::basic_string& in) - { - if (in.empty() || bad_) - return *this; - - if (in.size() > max_chunk_size) - { - bad_ = true; - return *this; - } - - if (chunk_total_ > max_chunk_size) - { - bad_ = true; - return *this; - } - - const auto& sz = in.size(); - const static auto size_max_chunk = max_chunk_size; - const auto& ptr = in.data(); - - if (chunk_total_ < size_max_chunk) - { - std::memcpy(chunk_ + chunk_total_, ptr, sz); - chunk_total_ += sz; - } - - return *this; - } - - /// @brief Convert to basic_string or return from cache. - std::basic_string str() const noexcept - { - static std::basic_string ret; - const auto& sz = ret.size(); - - if (chunk_total_ > sz) - ret.clear(); - else - return ret; - - ret = chunk_; - - return ret; - } - - void print() noexcept - { - ocl::io::print(chunk_); - } - }; - - template - inline void print(basic_chunk_string& fmt) noexcept - { - fmt.print(); - } -} // namespace ocl -#endif // ifndef OCL_UTILITY_CHUNK_STRING_HPP diff --git a/include/ocl/core/handler.hpp b/include/ocl/core/handler.hpp deleted file mode 100644 index e31f0d4..0000000 --- a/include/ocl/core/handler.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * File: core/handler.hpp - * Purpose: Handler container. - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License. - */ - -#ifndef _OCL_ERROR_HANDLER_HPP -#define _OCL_ERROR_HANDLER_HPP - -#include -#include -#include - -namespace ocl -{ - struct handler; - - struct handler - { - private: - template - void handle_impl(T element) {} - - public: - using error_type = std::exception; - - explicit handler() = default; - virtual ~handler() = default; - - handler& operator=(const handler&) = default; - handler(const handler&) = default; - - template - void operator()(T element) - { - this->handle_impl(element); - } - }; -} // namespace ocl - -#endif // ifndef _OCL_ERROR_HANDLER_HPP -- cgit v1.2.3