vecmem 1.18.0
Loading...
Searching...
No Matches
buffer.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023-2025 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9// Local include(s).
10#include "vecmem/containers/data/buffer_type.hpp"
11#include "vecmem/edm/details/schema_traits.hpp"
12#include "vecmem/edm/schema.hpp"
13#include "vecmem/edm/view.hpp"
14#include "vecmem/memory/memory_resource.hpp"
15#include "vecmem/memory/unique_ptr.hpp"
16#include "vecmem/utils/types.hpp"
17
18// System include(s).
19#include <type_traits>
20#include <utility>
21#include <vector>
22
23namespace vecmem {
24namespace edm {
25
27template <typename T>
28class buffer;
29
159template <typename... VARTYPES>
160class buffer<schema<VARTYPES...>> : public view<schema<VARTYPES...>> {
161
162 // Make sure that all variable types are supported. It needs to be possible
163 // to copy the contents of all variables with simple memory copies, and
164 // it has to be possible to trivially destruct all objects.
165 static_assert(
166 std::conjunction_v<
167 std::is_trivially_destructible<typename VARTYPES::type>...>,
168 "Unsupported variable type");
169 static_assert(std::conjunction_v<std::is_trivially_assignable<
170 std::add_lvalue_reference_t<typename VARTYPES::type>,
171 typename VARTYPES::type>...>,
172 "Unsupported variable type");
173
174public:
180 using size_type = typename view_type::size_type;
183
185 buffer() = default;
188
191
198 VECMEM_HOST
199 buffer(
200 size_type capacity, memory_resource& mr,
201 vecmem::data::buffer_type type = vecmem::data::buffer_type::fixed_size);
202
217 template <typename SIZE_TYPE = std::size_t,
221 bool> = true>
222 VECMEM_HOST buffer(
224 memory_resource& mr, memory_resource* host_mr = nullptr,
225 vecmem::data::buffer_type type = vecmem::data::buffer_type::fixed_size);
226
227private:
229 template <typename SIZE_TYPE = std::size_t,
231 std::size_t... INDICES>
232 VECMEM_HOST void setup_fixed(
234 memory_resource& mr, memory_resource* host_mr,
235 std::index_sequence<INDICES...>);
237 template <typename SIZE_TYPE = std::size_t,
239 std::size_t... INDICES>
240 VECMEM_HOST void setup_resizable(
242 memory_resource& mr, memory_resource* host_mr,
243 std::index_sequence<INDICES...>);
244
246 memory_type m_memory;
248 memory_type m_host_memory;
249
250}; // class buffer
251
252} // namespace edm
253
261VECMEM_HOST edm::view<edm::schema<VARTYPES...>> get_data(
262 edm::buffer<edm::schema<VARTYPES...>>& buffer);
263
271VECMEM_HOST edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>
272get_data(const edm::buffer<edm::schema<VARTYPES...>>& buffer);
273
274} // namespace vecmem
275
276// Include the implementation.
277#include "vecmem/edm/impl/buffer.ipp"
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
buffer()=default
Default constructor.
buffer(buffer &&) noexcept=default
Move constructor.
typename view_type::size_type size_type
Size type used for the container.
Definition buffer.hpp:180
Technical base type for buffer<schema<VARTYPES...>>
Definition buffer.hpp:28
Technical base type for data<schema<VARTYPES...>>
Definition data.hpp:25
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:29
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
VECMEM_HOST data::vector_view< T > get_data(array< T, N > &a)
Helper function creating a vecmem::data::vector_view object.
Definition array.ipp:217
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46