summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/core
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-29 14:53:01 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-11-29 14:54:13 -0500
commita8e99f3a783069cf85b626c6cfb2fbe83ae4fd44 (patch)
tree8322b0d20dd02660c3f26fcfd37c2cc4dcd33cda /include/ocl/core
parent463a0c01f96d86c9c91f02903bc1d194c5e55b15 (diff)
chore: new version of OCL and codebase cleanup.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/ocl/core')
-rw-r--r--include/ocl/core/allocator_op.hpp74
-rw-r--r--include/ocl/core/chunk_string.hpp2
-rw-r--r--include/ocl/core/equiv.hpp106
-rw-r--r--include/ocl/core/error.hpp21
-rw-r--r--include/ocl/core/error_handler.hpp1
-rw-r--r--include/ocl/core/opt.hpp134
6 files changed, 336 insertions, 2 deletions
diff --git a/include/ocl/core/allocator_op.hpp b/include/ocl/core/allocator_op.hpp
new file mode 100644
index 0000000..8fb8ce9
--- /dev/null
+++ b/include/ocl/core/allocator_op.hpp
@@ -0,0 +1,74 @@
+/*
+ * File: core/allocator_op.hpp
+ * Purpose: Allocator System container.
+ * 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_ALLOCATOR_SYSTEM_HPP
+#define _OCL_ALLOCATOR_SYSTEM_HPP
+
+#include <core/config.hpp>
+#include <memory>
+
+namespace ocl
+{
+ template <typename type>
+ struct new_op final
+ {
+ inline auto operator()() -> type*
+ {
+ return new type;
+ }
+
+ template <typename... var_type>
+ inline auto var_alloc(var_type... args) -> type*
+ {
+ return new type{args...};
+ }
+ };
+
+ template <typename type>
+ struct delete_op final
+ {
+ inline auto operator()(type* t) -> void
+ {
+ delete t;
+ }
+ };
+
+ template <typename ret_type, typename allocator_new, typename allocator_delete>
+ class allocator_op
+ {
+ allocator_new m_alloc_{};
+ allocator_delete m_free_{};
+
+ public:
+ allocator_op() = default;
+ ~allocator_op() = default;
+
+ allocator_op& operator=(const allocator_op&) = delete;
+ allocator_op(const allocator_op&) = delete;
+
+ ret_type* claim()
+ {
+ return m_alloc_();
+ }
+
+ template <typename... var_type>
+ auto construct(var_type... args) -> std::shared_ptr<ret_type>
+ {
+ return std::shared_ptr<ret_type>(m_alloc_.template var_alloc<var_type...>(args...), allocator_delete{});
+ }
+
+ void unclaim(ret_type* ptr)
+ {
+ m_free_(ptr);
+ }
+ };
+
+ template <typename type>
+ using allocator_type = allocator_op<type, new_op<type>, 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
index ebcfda3..17d81bd 100644
--- a/include/ocl/core/chunk_string.hpp
+++ b/include/ocl/core/chunk_string.hpp
@@ -1,6 +1,6 @@
/*
* File: core/chunk_string.hpp
- * Purpose: String implementation for the OCL C++ library.
+ * Purpose: Chunked String implementation for the OCL C++ library.
* Author: Amlal El Mahrouss (amlal@nekernel.org)
* Copyright 2025, Amlal El Mahrouss
*/
diff --git a/include/ocl/core/equiv.hpp b/include/ocl/core/equiv.hpp
new file mode 100644
index 0000000..f98d86d
--- /dev/null
+++ b/include/ocl/core/equiv.hpp
@@ -0,0 +1,106 @@
+/*
+ * File: equiv.hpp
+ * Purpose: Equivalence header.
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
+ */
+
+#pragma once
+
+#include <core/config.hpp>
+
+/// @brief OCL equivalence namespace.
+namespace ocl::equiv
+{
+ template <typename T>
+ struct basic_hash_trait
+ {
+ /// @brief hash from T's result_type.
+ static typename T::result_type hash()
+ {
+ static T val;
+ return val.hash();
+ }
+ };
+
+ template <typename T, typename U>
+ struct is_same
+ {
+ static constexpr bool value = false;
+
+ /// @brief check if hash matches what we expect.
+ constexpr bool operator()() noexcept
+ {
+ return T::hash() == U::hash();
+ }
+ };
+
+ template <typename T>
+ struct is_same<T, T>
+ {
+ static constexpr bool value = true;
+ };
+
+ template <typename T, typename U>
+ struct is_not_same
+ {
+ static constexpr bool value = true;
+
+ constexpr bool operator()() noexcept
+ {
+ return T::hash() != U::hash();
+ }
+ };
+
+ template <typename T>
+ struct is_not_same<T, T>
+ {
+ static constexpr bool value = false;
+ };
+
+ template <typename T>
+ struct equiv_is_int8
+ {
+ private:
+ T left_ = 127, right_ = 127;
+
+ public:
+ using result_type = T;
+
+ constexpr result_type hash()
+ {
+ return (left_ + right_) < 1;
+ }
+ };
+
+ template <typename T>
+ struct equiv_not_int8
+ {
+ private:
+ // these shall overflow if not int8.
+ T left_ = 127, right_ = 127;
+
+ public:
+ using result_type = T;
+
+ constexpr result_type hash()
+ {
+ return (left_ + right_) > 0;
+ }
+ };
+
+ template <typename T>
+ struct equiv_is_real
+ {
+ private:
+ T left_ = 5, right_ = 3;
+
+ public:
+ using result_type = T;
+
+ constexpr result_type hash()
+ {
+ return left_ / right_ == 1;
+ }
+ };
+} // namespace ocl::equiv
diff --git a/include/ocl/core/error.hpp b/include/ocl/core/error.hpp
new file mode 100644
index 0000000..cf038f8
--- /dev/null
+++ b/include/ocl/core/error.hpp
@@ -0,0 +1,21 @@
+/*
+ * File: opt.hpp
+ * Author: Amlal El Mahrouss,
+ * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License
+ */
+
+#ifndef _OCL_ERR_HPP
+#define _OCL_ERR_HPP
+
+#include <stdexcept>
+#include <core/error_handler.hpp>
+
+namespace ocl::error
+{
+ using runtime_error = std::runtime_error;
+ using fix_error = runtime_error;
+ using math_error = runtime_error;
+ using cgi_error = runtime_error;
+} // namespace ocl::error
+
+#endif // _OCL_ERR_HPP \ No newline at end of file
diff --git a/include/ocl/core/error_handler.hpp b/include/ocl/core/error_handler.hpp
index dcb0c89..971d91c 100644
--- a/include/ocl/core/error_handler.hpp
+++ b/include/ocl/core/error_handler.hpp
@@ -40,7 +40,6 @@ namespace ocl
}
};
- using standard_error_handler = basic_error_handler;
using error_handler_type = basic_error_handler;
} // namespace ocl
diff --git a/include/ocl/core/opt.hpp b/include/ocl/core/opt.hpp
new file mode 100644
index 0000000..506f582
--- /dev/null
+++ b/include/ocl/core/opt.hpp
@@ -0,0 +1,134 @@
+/*
+ * File: opt.hpp
+ * Author: Amlal El Mahrouss,
+ * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License
+ */
+
+#ifndef _OCL_OPT_HPP
+#define _OCL_OPT_HPP
+
+#include <core/config.hpp>
+#include <utility>
+
+namespace ocl
+{
+ enum class return_type
+ {
+ invalid = 0,
+ okay = 100,
+ err,
+ count = err - okay + 1,
+ };
+
+ template <typename char_type = char>
+ struct opt final
+ {
+ explicit opt(const return_type& return_type)
+ : m_ret(return_type)
+ {
+ }
+
+ opt& expect(const char_type* input)
+ {
+ if (m_ret == return_type::err)
+ {
+ throw std::runtime_error(input ? input : "opt::error");
+ }
+
+ return *this;
+ }
+
+ template <typename ErrorHandler>
+ opt& expect_or_handle(const char_type* input)
+ {
+ if (m_ret == return_type::err)
+ {
+ ErrorHandler err_handler;
+ err_handler(input ? input : "opt::error");
+ }
+
+ return *this;
+ }
+
+ private:
+ return_type m_ret{return_type::invalid};
+ };
+
+ template <typename Teller, typename... Lst>
+ inline return_type eval(Teller tell, Lst&&... arg)
+ {
+ return tell(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ }
+
+ namespace traits
+ {
+ struct int_eq_teller
+ {
+ explicit int_eq_teller()
+ {
+ }
+
+ bool operator()(int a, int b)
+ {
+ return (a == b);
+ }
+ };
+
+ struct int_greater_than_teller
+ {
+ explicit int_greater_than_teller()
+ {
+ }
+
+ bool operator()(int a, int b)
+ {
+ return (a > b);
+ }
+ };
+
+ struct int_less_than_teller
+ {
+ explicit int_less_than_teller()
+ {
+ }
+
+ bool operator()(int a, int b)
+ {
+ return (a < b);
+ }
+ };
+ } // namespace traits
+
+ template <typename... Lst>
+ inline return_type eval_less_than(Lst&&... arg)
+ {
+ static traits::int_less_than_teller eq;
+ return eq(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ }
+
+ template <typename... Lst>
+ inline return_type eval_eq(Lst&&... arg)
+ {
+ static traits::int_eq_teller less_than;
+ return less_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ }
+
+ template <typename... Lst>
+ inline return_type eval_greater_than(Lst&&... arg)
+ {
+ static traits::int_greater_than_teller greater_than;
+ return greater_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ }
+
+ inline return_type eval_true() noexcept
+ {
+ return return_type::okay;
+ }
+
+ inline return_type eval_false() noexcept
+ {
+ return return_type::err;
+ }
+} // namespace ocl
+
+#endif /* ifndef _OCL_OPT_HPP */ \ No newline at end of file