ATLAS Offline Software
Loading...
Searching...
No Matches
AuxDataTraits.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
12
13
14#ifndef ATHCONTAINERS_AUXDATATRAITS_H
15#define ATHCONTAINERS_AUXDATATRAITS_H
16
17
18#include "CxxUtils/span.h"
19#include <vector>
20#include <cstdlib>
21
22
23namespace SG {
24
25
27template <class T>
28using AuxAllocator_t = std::allocator<T>;
29constexpr const char* auxAllocatorNamePrefix = "std::allocator<";
30
31
38template <class T, class ALLOC = AuxAllocator_t<T> >
40{
41public:
43 using element_type = T;
44
48
50 using allocator_type = ALLOC;
51
53 using vector_type = std::vector<T, allocator_type>;
54 using container_value_type = typename vector_type::value_type;
55
57 using container_pointer_type = typename vector_type::pointer;
58 using const_container_pointer_type = typename vector_type::const_pointer;
59
62 static reference_type index (void* ptr, size_t ndx)
63 {
64 return reinterpret_cast<container_pointer_type>(ptr)[ndx];
65 }
66
69 static const_reference_type index (const void* ptr, size_t ndx)
70 {
71 return reinterpret_cast<const_container_pointer_type>(ptr)[ndx];
72 }
73
76};
77
78
87template <class ALLOC>
88class AuxDataTraits<bool, ALLOC>
89{
90public:
92 using element_type = bool;
93
97
99 using allocator_type = typename std::allocator_traits<ALLOC>::template rebind_alloc<char>;
100
102 using vector_type = std::vector<char, allocator_type>;
103 using container_value_type = typename vector_type::value_type;
104
106 using container_pointer_type = typename vector_type::pointer;
107 using const_container_pointer_type = typename vector_type::const_pointer;
108
111 static reference_type index (void* ptr, size_t ndx)
112 {
113 return reinterpret_cast<bool*>(ptr)[ndx];
114 }
115
118 static const_reference_type index (const void* ptr, size_t ndx)
119 {
120 return reinterpret_cast<const bool*>(ptr)[ndx];
121 }
122
125};
126
127
133template <class T>
134struct Zero
135{
136 static T zero()
137 {
138 return T();
139 }
140};
141
142
143} // namespace SG
144
145
146#endif // not ATHCONTAINERS_AUXDATATRAITS_H
Simplified version of the C++20 std::span.
Definition span.h:61
const element_type & const_reference_type
typename std::allocator_traits< ALLOC >::template rebind_alloc< char > allocator_type
Allocator type used to store this variable.
CxxUtils::span< container_value_type > span
typename vector_type::pointer container_pointer_type
Pointers to the data within the container.
bool element_type
The type the user sees.
element_type & reference_type
Reference types returned by aux data accessors.
static const_reference_type index(const void *ptr, size_t ndx)
Look up an element in the container by index.
CxxUtils::span< const container_value_type > const_span
typename vector_type::value_type container_value_type
std::vector< char, allocator_type > vector_type
Container type used to store this variable.
static reference_type index(void *ptr, size_t ndx)
Look up an element in the container by index.
typename vector_type::const_pointer const_container_pointer_type
Allow customizing how aux data types are treated.
const element_type & const_reference_type
typename vector_type::pointer container_pointer_type
Pointers to the data within the container.
CxxUtils::span< container_value_type > span
typename vector_type::value_type container_value_type
CxxUtils::span< const container_value_type > const_span
element_type & reference_type
Reference types returned by aux data accessors.
std::vector< T, allocator_type > vector_type
Container type used to store this variable.
T element_type
The type the user sees.
ALLOC allocator_type
Allocator type used to store this variable.
typename vector_type::const_pointer const_container_pointer_type
static const_reference_type index(const void *ptr, size_t ndx)
Look up an element in the container by index.
static reference_type index(void *ptr, size_t ndx)
Look up an element in the container by index.
Forward declaration.
constexpr const char * auxAllocatorNamePrefix
std::allocator< T > AuxAllocator_t
The default allocator type to use for auxiliary variables.
Simplified version of the C++20 std::span.
Helper to specialize how to make an initialized instance of T.
static T zero()