diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-09-04 11:25:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-04 11:25:04 +0200 |
| commit | 6789dd7d88a192e3f55b95798cb393e7d12f368a (patch) | |
| tree | 7f04815ad5214f97d0fb2becceceed7ce8089b3d /dev/lib/core | |
| parent | 443588a42fe9cf48b5f63184b94afe483cb0e761 (diff) | |
| parent | fda7082c54ad46a56ac885d4686b82bad8dbc7c9 (diff) | |
Merge pull request #4 from amlel-el-mahrouss/devv1.0.43
OCL — v1.0.43
Diffstat (limited to 'dev/lib/core')
| -rw-r--r-- | dev/lib/core/allocator_system.hpp | 75 | ||||
| -rw-r--r-- | dev/lib/core/error_handler.hpp | 35 | ||||
| -rw-r--r-- | dev/lib/core/includes.hpp | 10 |
3 files changed, 114 insertions, 6 deletions
diff --git a/dev/lib/core/allocator_system.hpp b/dev/lib/core/allocator_system.hpp new file mode 100644 index 0000000..1243ed5 --- /dev/null +++ b/dev/lib/core/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 <lib/core/includes.hpp> +#include <stdexcept> +#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_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 <typename... var_type> + auto construct(var_type... args) -> std::shared_ptr<ret_type> + { + return std::shared_ptr<ret_type>(alloc_.template var_alloc<var_type...>(args...), allocator_delete{}); + } + + void unclaim(ret_type* ptr) + { + del_(ptr); + } + }; + + template <typename type> + using standard_allocator_type = allocator_system<type, new_op<type>, delete_op<type>>; +} // namespace ocl + +#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP diff --git a/dev/lib/core/error_handler.hpp b/dev/lib/core/error_handler.hpp new file mode 100644 index 0000000..593e54a --- /dev/null +++ b/dev/lib/core/error_handler.hpp @@ -0,0 +1,35 @@ +/* +* File: core/basic_error_handler.hpp +* Purpose: Error handler container. +* Author: Amlal El Mahrouss (amlal@nekernel.org) +* Copyright 2025, Amlal El Mahrouss. +*/ + +#ifndef _OCL_ERROR_HANDLER_HPP +#define _OCL_ERROR_HANDLER_HPP + +#include <lib/core/includes.hpp> +#include <stdexcept> + +namespace ocl +{ + struct basic_error_handler; + + struct basic_error_handler + { + explicit basic_error_handler() = default; + virtual ~basic_error_handler() = default; + + basic_error_handler& operator=(const basic_error_handler&) = delete; + basic_error_handler(const basic_error_handler&) = delete; + + virtual void operator()(const std::basic_string<char>& msg) + { + ((void)msg); + } + }; + + using standard_error_handler = basic_error_handler; +} // namespace ocl + +#endif // ifndef _OCL_ERROR_HANDLER_HPP diff --git a/dev/lib/core/includes.hpp b/dev/lib/core/includes.hpp index e482a7c..f988fc1 100644 --- a/dev/lib/core/includes.hpp +++ b/dev/lib/core/includes.hpp @@ -1,8 +1,8 @@ /* * File: core/includes.hpp - * Purpose: Core includes for the SOCL library. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + * Purpose: Core includes for the OCL library. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss */ #pragma once @@ -11,6 +11,4 @@ #include <boost/core/nvp.hpp> #include <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> -#include <memory> -#include <utility> -#include <filesystem> +#include <boost/container/allocator.hpp> |
