summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/ocl/core/allocator_op.hpp26
-rw-r--r--include/ocl/core/chunk_string.hpp122
-rw-r--r--include/ocl/core/handler.hpp42
-rw-r--r--tests/chunk_string/CMakeLists.txt25
-rw-r--r--tests/chunk_string/chunk_test.cc22
5 files changed, 9 insertions, 228 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
diff --git a/tests/chunk_string/CMakeLists.txt b/tests/chunk_string/CMakeLists.txt
deleted file mode 100644
index 53a9add..0000000
--- a/tests/chunk_string/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-cmake_minimum_required(VERSION 3.27)
-project(BasicChunkUsage LANGUAGES CXX)
-
-# find_package(Boost REQUIRED COMPONENTS container)
-
-include(FetchContent)
-FetchContent_Declare(
- googletest
- URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
-)
-
-# For Windows: Prevent overriding the parent project's compiler/linker settings
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-FetchContent_MakeAvailable(googletest)
-
-enable_testing()
-
-add_executable(BasicChunkUsage chunk_test.cc)
-target_link_libraries(BasicChunkUsage PRIVATE gtest_main)
-
-set_property(TARGET BasicChunkUsage PROPERTY CXX_STANDARD 20)
-target_include_directories(BasicChunkUsage PUBLIC ../../include/ocl)
-
-include(GoogleTest)
-gtest_discover_tests(BasicChunkUsage)
diff --git a/tests/chunk_string/chunk_test.cc b/tests/chunk_string/chunk_test.cc
deleted file mode 100644
index 37f5cb1..0000000
--- a/tests/chunk_string/chunk_test.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * File: tests/chunk_test.cc
- * Purpose: Chunk unit tests in C++
- * Author: Amlal El Mahrouss (amlal@nekernel.org)
- * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
- */
-
-#include <io/print.hpp>
-#include <gtest/gtest.h>
-#include <core/chunk_string.hpp>
-
-const char* test_string = "HELLO, WORLD!\r\n";
-const auto iterations = 1024000;
-const auto limit = 30;
-
-TEST(ChunkTest, BasicChunkUsage)
-{
- ocl::basic_chunk_string<char, iterations> optimized;
- optimized += test_string;
-
- EXPECT_TRUE(optimized.str() == test_string);
-}