ATLAS Offline Software
Loading...
Searching...
No Matches
PackedLinkVector.icc
Go to the documentation of this file.
1/**
2 * @file AthContainers/tools/PackedLinkVector.icc
3 * @author scott snyder <snyder@bnl.gov>
4 * @date Sep, 2023
5 * @brief Implementation of @c IAuxTypeVector for @c PackedLink types.
6 */
7
8
9#include "AthContainers/AuxTypeRegistry.h"
10
11
12namespace SG {
13
14
15/**
16 * @brief Constructor.
17 * @param auxid The auxid of the variable this vector represents.
18 * @param vecPtr Pointer to the object.
19 * @param linkedVec Interface for the linked vector of DataLinks.
20 * @param ownFlag If true, take ownership of the object.
21 */
22template <class CONT, class ALLOC>
23PackedLinkVectorHolder<CONT, ALLOC>::PackedLinkVectorHolder
24 (auxid_t auxid,
25 vector_type* vecPtr,
26 IAuxTypeVector* linkedVec,
27 bool ownFlag)
28 : Base (auxid, vecPtr, ownFlag, false),
29 m_linkedVec (linkedVec)
30{
31}
32
33
34/**
35 * @brief Insert elements into the vector via move semantics.
36 * @param pos The starting index of the insertion.
37 * @param src Start of the vector containing the range of elements to insert.
38 * @param src_pos Position of the first element to insert.
39 * @param src_n Number of elements to insert.
40 * @param srcStore The source store.
41 *
42 * The size of the container will be increased by @c src_n, with the elements
43 * starting at @c pos copied to @c pos+src_n.
44 *
45 * The contents of the source range will then be moved to our vector
46 * starting at @c pos. This will be done via move semantics if possible;
47 * otherwise, it will be done with a copy.
48 *
49 * Returns true if it is known that the vector's memory did not move,
50 * false otherwise.
51 */
52template <class CONT, class ALLOC>
53bool PackedLinkVectorHolder<CONT, ALLOC>::insertMove
54 (size_t pos, void* src, size_t src_pos, size_t src_n,
55 IAuxStore& srcStore)
56{
57 bool ret = Base::insertMove (pos, src, src_pos, src_n, srcStore);
58 auto srcp = reinterpret_cast<element_type*> (src);
59 auto begp = srcp + src_pos;
60 auto endp = begp + src_n;
61 size_t n = std::distance (begp, endp);
62 vector_type& vec = this->vec();
63
64 const IAuxTypeVector* srcLv = srcStore.linkedVector (this->auxid());
65 typename Helper::const_DataLinkBase_span srcDLinks = Helper::getLinkBaseSpan (*srcLv);
66 ret &= Helper::updateLinks (*m_linkedVec, vec.data()+pos, n,
67 srcDLinks, nullptr);
68 return ret;
69}
70
71
72//*****************************************************************************
73
74
75/**
76 * @brief Constructor.
77 * @param auxid The auxid of the variable this vector represents.
78 * @param vecPtr Pointer to the object (of type @c CONT).
79 * @param linkedVec Interface for the linked vector of DataLinks.
80 * @param ownFlag If true, take ownership of the object.
81 */
82template <class CONT, class VALLOC, class VELT, class ALLOC>
83PackedLinkVVectorHolder<CONT, VALLOC, VELT, ALLOC>::PackedLinkVVectorHolder
84 (auxid_t auxid,
85 vector_type* vecPtr,
86 IAuxTypeVector* linkedVec,
87 bool ownFlag)
88 : Base (auxid, vecPtr, ownFlag, false),
89 m_linkedVec (linkedVec)
90{
91}
92
93
94/**
95 * @brief Insert elements into the vector via move semantics.
96 * @param pos The starting index of the insertion.
97 * @param src Start of the vector containing the range of elements to insert.
98 * @param src_pos Position of the first element to insert.
99 * @param src_n Number of elements to insert.
100 * @param srcStore The source store.
101 *
102 * @c beg and @c end define a range of container elements, with length
103 * @c len defined by the difference of the pointers divided by the
104 * element size.
105 *
106 * The size of the container will be increased by @c len, with the elements
107 * starting at @c pos copied to @c pos+len.
108 *
109 * The contents of the source range will then be moved to our vector
110 * starting at @c pos. This will be done via move semantics if possible;
111 * otherwise, it will be done with a copy.
112 *
113 * Returns true if it is known that the vector's memory did not move,
114 * false otherwise.
115 */
116template <class CONT, class VALLOC, class VELT, class ALLOC>
117bool PackedLinkVVectorHolder<CONT, VALLOC, VELT, ALLOC>::insertMove
118 (size_t pos, void* src, size_t src_pos, size_t src_n,
119 IAuxStore& srcStore)
120{
121 bool ret = Base::insertMove (pos, src, src_pos, src_n, srcStore);
122 auto srcp = reinterpret_cast<element_type*> (src);
123 auto begp = srcp + src_pos;
124 auto endp = begp + src_n;
125 size_t n = std::distance (begp, endp);
126 vector_type& vec = this->vec();
127 const IAuxTypeVector* srcLv = srcStore.linkedVector (this->auxid());
128 typename Helper::const_DataLinkBase_span srcDLinks = Helper::getLinkBaseSpan (*srcLv);
129
130 for (size_t i = pos; i < pos+n; ++i) {
131 ret &= Helper::updateLinks (*m_linkedVec, vec[i].data(), vec[i].size(),
132 srcDLinks, nullptr);
133 }
134 return ret;
135}
136
137
138//*****************************************************************************
139
140
141/**
142 * @brief Constructor. Makes a new vector.
143 * @param auxid The auxid of the variable this vector represents.
144 * @param size Initial size of the new vector.
145 * @param capacity Initial capacity of the new vector.
146 * @param linkedVec Ownership of the linked vector.
147 */
148template <class HOLDER>
149PackedLinkVectorT<HOLDER>::PackedLinkVectorT (auxid_t auxid,
150 size_t size,
151 size_t capacity,
152 std::unique_ptr<IAuxTypeVector> linkedVec)
153 : Base (auxid, &m_vec, linkedVec.get(), false),
154 m_linkedVecHolder (std::move (linkedVec))
155{
156 m_vec.reserve (capacity);
157 m_vec.resize (size);
158}
159
160
161/**
162 * @brief Copy constructor.
163 */
164template <class HOLDER>
165PackedLinkVectorT<HOLDER>::PackedLinkVectorT (const PackedLinkVectorT& other)
166 : Base (other.auxid(), &m_vec, false, false),
167 m_vec (other.m_vec),
168 m_linkedVecHolder (other.m_linkedVec->clone())
169{
170 Base::m_linkedVec = m_linkedVecHolder.get();
171}
172
173
174/**
175 * @brief Move constructor.
176 */
177template <class HOLDER>
178PackedLinkVectorT<HOLDER>::PackedLinkVectorT (PackedLinkVectorT&& other)
179 : Base (other.auxid(), &m_vec, false, other.m_linkedVec),
180 m_vec (std::move (other.m_vec)),
181 m_linkedVecHolder (std::move (other.m_linkedVecHolder))
182{
183}
184
185
186/**
187 * @brief Make a copy of this vector.
188 */
189template <class HOLDER>
190inline
191std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::clone() const
192{
193 return std::make_unique<PackedLinkVectorT> (*this);
194}
195
196
197/**
198 * @brief Return ownership of the linked vector.
199 */
200template <class HOLDER>
201inline
202std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::linkedVector()
203{
204 return std::move (m_linkedVecHolder);
205}
206
207
208} // namespace SG