summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ocl/allocator_op.hpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/include/ocl/allocator_op.hpp b/include/ocl/allocator_op.hpp
index eff3bac..ed6ae90 100644
--- a/include/ocl/allocator_op.hpp
+++ b/include/ocl/allocator_op.hpp
@@ -17,34 +17,40 @@ namespace ocl
template <typename type>
struct global_new_op final
{
- inline auto operator()() -> type*
+ using pointer_type = type*;
+
+ auto alloc() -> pointer_type
{
return new type;
}
+ template <size_t N>
+ auto array_alloc() -> pointer_type
+ {
+ return new type[N];
+ }
+
template <typename... var_type>
- inline auto var_alloc(var_type&&... args) -> type*
+ auto var_alloc(var_type&&... args) -> pointer_type
{
return new type{std::forward<var_type>(args)...};
}
};
- /// @note these are guidelines on deleting a resource
template <typename type>
- struct global_delete_op final
+ struct global_array_delete_op final
{
- inline auto operator()(type* t) -> void
+ using pointer_type = type*;
+
+ auto operator()(pointer_type t) -> void
{
- delete t;
+ delete[] t;
}
};
template <typename ret_type, typename allocator_new, typename allocator_delete>
class allocator_op
{
- allocator_new alloc_op_{};
- allocator_delete free_op_{};
-
public:
allocator_op() = default;
~allocator_op() = default;
@@ -53,14 +59,21 @@ namespace ocl
allocator_op(const allocator_op&) = delete;
template <typename... var_type>
- auto construct(var_type&&... args) -> std::shared_ptr<ret_type>
+ auto construct_var(var_type... args)
{
- return std::shared_ptr<ret_type>(alloc_op_.template var_alloc<var_type...>(args...), free_op_);
+ return std::shared_ptr<ret_type>(allocator_new{}.template var_alloc<var_type...>(std::forward<var_type...>(args)...), allocator_delete{});
}
+
+ template<size_t N>
+ auto construct_array()
+ {
+ return std::shared_ptr<ret_type>(allocator_new{}.template array_alloc<N>(), allocator_delete{});
+ }
+
};
template <typename type>
- using allocator = allocator_op<type, global_new_op<type>, global_delete_op<type>>;
+ using allocator = allocator_op<type, global_new_op<type>, global_array_delete_op<type>>;
} // namespace ocl
#endif // ifndef __OCL_CORE_ALLOC \ No newline at end of file