2 * @file AthContainers/tools/PackedLinkVector.icc
3 * @author scott snyder <snyder@bnl.gov>
5 * @brief Implementation of @c IAuxTypeVector for @c PackedLink types.
9#include "AthContainers/AuxTypeRegistry.h"
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.
22template <class CONT, class ALLOC>
23PackedLinkVectorHolder<CONT, ALLOC>::PackedLinkVectorHolder
26 IAuxTypeVector* linkedVec,
28 : Base (auxid, vecPtr, ownFlag, false),
29 m_linkedVec (linkedVec)
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.
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.
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.
49 * Returns true if it is known that the vector's memory did not move,
52template <class CONT, class ALLOC>
53bool PackedLinkVectorHolder<CONT, ALLOC>::insertMove
54 (size_t pos, void* src, size_t src_pos, size_t src_n,
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();
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,
72//*****************************************************************************
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.
82template <class CONT, class VALLOC, class VELT, class ALLOC>
83PackedLinkVVectorHolder<CONT, VALLOC, VELT, ALLOC>::PackedLinkVVectorHolder
86 IAuxTypeVector* linkedVec,
88 : Base (auxid, vecPtr, ownFlag, false),
89 m_linkedVec (linkedVec)
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.
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
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.
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.
113 * Returns true if it is known that the vector's memory did not move,
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,
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);
130 for (size_t i = pos; i < pos+n; ++i) {
131 ret &= Helper::updateLinks (*m_linkedVec, vec[i].data(), vec[i].size(),
138//*****************************************************************************
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.
148template <class HOLDER>
149PackedLinkVectorT<HOLDER>::PackedLinkVectorT (auxid_t auxid,
152 std::unique_ptr<IAuxTypeVector> linkedVec)
153 : Base (auxid, &m_vec, linkedVec.get(), false),
154 m_linkedVecHolder (std::move (linkedVec))
156 m_vec.reserve (capacity);
162 * @brief Copy constructor.
164template <class HOLDER>
165PackedLinkVectorT<HOLDER>::PackedLinkVectorT (const PackedLinkVectorT& other)
166 : Base (other.auxid(), &m_vec, false, false),
168 m_linkedVecHolder (other.m_linkedVec->clone())
170 Base::m_linkedVec = m_linkedVecHolder.get();
175 * @brief Move constructor.
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))
187 * @brief Make a copy of this vector.
189template <class HOLDER>
191std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::clone() const
193 return std::make_unique<PackedLinkVectorT> (*this);
198 * @brief Return ownership of the linked vector.
200template <class HOLDER>
202std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::linkedVector()
204 return std::move (m_linkedVecHolder);