vecmem 1.14.0
Loading...
Searching...
No Matches
data_traits.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023 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/jagged_vector_data.hpp"
11#include "vecmem/edm/details/schema_traits.hpp"
12#include "vecmem/edm/details/view_traits.hpp"
13#include "vecmem/edm/schema.hpp"
14#include "vecmem/memory/memory_resource.hpp"
15#include "vecmem/utils/tuple.hpp"
16
17// System include(s).
18#include <tuple>
19#include <variant>
20
21namespace vecmem::edm::details {
22
25
26template <typename TYPE>
27struct data_type {
28 using type = std::monostate;
29}; // struct data_type
30
31template <typename TYPE>
34}; // struct data_type
35
37
40
41template <typename TYPE>
42struct data_alloc {
43 static typename data_type<TYPE>::type make(std::size_t, memory_resource&) {
44 return {};
45 }
46}; // struct data_alloc
47
48template <typename TYPE>
49struct data_alloc<type::jagged_vector<TYPE>> {
50 static typename data_type<type::jagged_vector<TYPE>>::type make(
51 std::size_t size, memory_resource& mr) {
52 return {size, mr};
53 }
54}; // struct data_alloc
55
57
59template <typename... VARTYPES, std::size_t INDEX, std::size_t... Is>
60void data_view_assign(
62 const std::tuple<typename data_type<VARTYPES>::type...>& data,
63 std::index_sequence<INDEX, Is...>) {
64
65 // Make the assignments just for jagged vector variables.
66 if constexpr (type::details::is_jagged_vector<typename std::tuple_element<
67 INDEX, std::tuple<VARTYPES...>>::type>::value) {
68 get<INDEX>(view) = std::get<INDEX>(data);
69 }
70 // Terminate, or continue.
71 if constexpr (sizeof...(Is) > 0) {
72 data_view_assign<VARTYPES...>(view, data, std::index_sequence<Is...>{});
73 }
74}
75
76} // namespace vecmem::edm::details
A data wrapper for jagged vectors.
Definition jagged_vector_data.hpp:30
Technical base type for data<schema<VARTYPES...>>
Definition data.hpp:25
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:28
vector< vector< T > > jagged_vector
Alias type for jagged vectors with our polymorphic allocator.
Definition jagged_vector.hpp:30
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
Definition data_traits.hpp:42
Definition data_traits.hpp:27
Definition view_traits.hpp:33
Definition schema_traits.hpp:82
Default tuple type.
Definition tuple.hpp:24