diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-30 07:09:34 -0500 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-30 07:09:34 -0500 |
| commit | f8f05ded6a1da18052a6154393710d55ff6ce8bd (patch) | |
| tree | 346acdde979cbc455146a5e5cbba3453412e4280 /include | |
| parent | 82772695a621f7f07ce654f676d14ca70b908e63 (diff) | |
chore: new improvements over the previous impelemntations of allocator_op.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/ocl/core/allocator_op.hpp | 26 | ||||
| -rw-r--r-- | include/ocl/core/chunk_string.hpp | 122 | ||||
| -rw-r--r-- | include/ocl/core/handler.hpp | 42 |
3 files changed, 9 insertions, 181 deletions
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 <typename type> - struct new_op final + struct global_new_op final { inline auto operator()() -> type* { @@ -22,14 +23,15 @@ namespace ocl } template <typename... var_type> - 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<var_type>(args)...}; } }; + /// @note these are guidelines on deleting a resource template <typename type> - 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 <typename... var_type> - auto construct(var_type... args) -> std::shared_ptr<ret_type> - { - return std::shared_ptr<ret_type>(alloc_op_.template var_alloc<var_type...>(args...), allocator_delete{}); - } - - void unclaim(ret_type* ptr) + auto construct(var_type&&... args) -> std::shared_ptr<ret_type> { - free_op_(ptr); + return std::shared_ptr<ret_type>(alloc_op_.template var_alloc<var_type...>(args...), free_op_); } }; template <typename type> - using allocator_type = allocator_op<type, new_op<type>, delete_op<type>>; + using allocator_type = allocator_op<type, global_new_op<type>, global_delete_op<type>>; } // 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 <core/config.hpp> -#include <io/print.hpp> -#include <cstring> - -namespace ocl -{ - template <typename char_type, std::size_t max_chunk_size = 8196> - class basic_chunk_string; - - template <typename char_type, std::size_t max_chunk_size> - 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<char_type>& 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<char_type>(in)); - - return *this; - } - - basic_chunk_string& operator+=(const std::basic_string<char_type>& 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<char_type> str() const noexcept - { - static std::basic_string<char_type> 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 <typename char_type> - inline void print(basic_chunk_string<char_type>& 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 <core/config.hpp> -#include <io/print.hpp> -#include <exception> - -namespace ocl -{ - struct handler; - - struct handler - { - private: - template <typename T> - 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 <typename T> - void operator()(T element) - { - this->handle_impl<T>(element); - } - }; -} // namespace ocl - -#endif // ifndef _OCL_ERROR_HANDLER_HPP |
