3#ifndef LALA_CORE_ABSTRACT_DEPS_HPP
4#define LALA_CORE_ABSTRACT_DEPS_HPP
6#include "battery/utility.hpp"
7#include "battery/vector.hpp"
8#include "battery/string.hpp"
9#include "battery/string.hpp"
10#include "battery/tuple.hpp"
11#include "battery/variant.hpp"
17using abstract_ptr = battery::shared_ptr<A, typename A::allocator_type>;
26template<
class... Allocators>
30 constexpr static size_t n = battery::tuple_size<battery::tuple<Allocators...>>{};
31 static_assert(
n > 0,
"AbstractDeps must have a non-empty list of allocators.");
34 using allocator_type =
typename battery::tuple_element<0, battery::tuple<Allocators...>>::type;
38 CUDA
virtual ~dep_erasure() {}
42 struct dep_holder : dep_erasure {
45 CUDA
virtual ~dep_holder() {}
49 battery::vector<battery::unique_ptr<dep_erasure, allocator_type>,
allocator_type> deps;
57 CUDA
AbstractDeps(
bool shared_copy,
const Allocators&... allocators)
58 : shared_copy(shared_copy)
59 , allocators(allocators...)
60 , deps(
battery::get<0>(this->allocators))
77 assert(deps.size() > aty);
79 return static_cast<dep_holder<A>*
>(deps[aty].get())->a;
82 template<
class A2,
class A>
85 auto to_alloc = battery::get<typename A2::allocator_type>(allocators);
91 if(deps.size() <= a->aty() || !
static_cast<bool>(deps[a->aty()])) {
92 deps.resize(battery::max((
int)deps.size(), a->aty()+1));
94 A2* a2 =
static_cast<A2*
>(to_alloc.allocate(
sizeof(A2)));
95 new(a2) A2(*a, *
this);
96 dep_holder<A2>* dep_hold =
static_cast<dep_holder<A2>*
>(internal_alloc.allocate(
sizeof(dep_holder<A2>)));
97 new(dep_hold) dep_holder<A2>(a2);
98 deps[a->aty()] = battery::unique_ptr<dep_erasure, allocator_type>(
99 dep_hold, internal_alloc);
105 template <
class Alloc>
107 return battery::get<Alloc>(allocators);
Definition abstract_deps.hpp:28
CUDA Alloc get_allocator() const
Definition abstract_deps.hpp:106
CUDA AbstractDeps(bool shared_copy, const Allocators &... allocators)
Definition abstract_deps.hpp:57
CUDA abstract_ptr< A > extract(AType aty)
Definition abstract_deps.hpp:75
typename battery::tuple_element< 0, battery::tuple< Allocators... > >::type allocator_type
Definition abstract_deps.hpp:34
CUDA NI abstract_ptr< A2 > clone(const abstract_ptr< A > &a)
Definition abstract_deps.hpp:83
CUDA size_t size() const
Definition abstract_deps.hpp:66
CUDA bool is_shared_copy() const
Definition abstract_deps.hpp:70
CUDA AbstractDeps(const Allocators &... allocators)
Definition abstract_deps.hpp:63
battery::tuple< Allocators... > allocators_type
Definition abstract_deps.hpp:33
static constexpr size_t n
Definition abstract_deps.hpp:30
Definition abstract_deps.hpp:14
int AType
Definition sort.hpp:18
battery::shared_ptr< A, typename A::allocator_type > abstract_ptr
Definition abstract_deps.hpp:17
#define UNTYPED
Definition sort.hpp:21