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.
22 template <class CONT, class ALLOC>
23 PackedLinkVectorHolder<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 * @c beg and @c end define a range of container elements, with length
43 * @c len defined by the difference of the pointers divided by the
46 * The size of the container will be increased by @c len, with the elements
47 * starting at @c pos copied to @c pos+len.
49 * The contents of the source range will then be moved to our vector
50 * starting at @c pos. This will be done via move semantics if possible;
51 * otherwise, it will be done with a copy.
53 * Returns true if it is known that the vector's memory did not move,
56 template <class CONT, class ALLOC>
57 bool PackedLinkVectorHolder<CONT, ALLOC>::insertMove
58 (size_t pos, void* src, size_t src_pos, size_t src_n,
61 bool ret = Base::insertMove (pos, src, src_pos, src_n, srcStore);
62 auto srcp = reinterpret_cast<element_type*> (src);
63 auto begp = srcp + src_pos;
64 auto endp = begp + src_n;
65 size_t n = std::distance (begp, endp);
66 vector_type& vec = this->vec();
68 const IAuxTypeVector* srcLv = srcStore.linkedVector (this->auxid());
69 typename Helper::const_DataLinkBase_span srcDLinks = Helper::getLinkBaseSpan (*srcLv);
70 ret &= Helper::updateLinks (*m_linkedVec, vec.data()+pos, n,
76 //*****************************************************************************
81 * @param auxid The auxid of the variable this vector represents.
82 * @param vecPtr Pointer to the object (of type @c CONT).
83 * @param linkedVec Interface for the linked vector of DataLinks.
84 * @param ownFlag If true, take ownership of the object.
86 template <class CONT, class VALLOC, class VELT, class ALLOC>
87 PackedLinkVVectorHolder<CONT, VALLOC, VELT, ALLOC>::PackedLinkVVectorHolder
90 IAuxTypeVector* linkedVec,
92 : Base (auxid, vecPtr, ownFlag, false),
93 m_linkedVec (linkedVec)
99 * @brief Insert elements into the vector via move semantics.
100 * @param pos The starting index of the insertion.
101 * @param src Start of the vector containing the range of elements to insert.
102 * @param src_pos Position of the first element to insert.
103 * @param src_n Number of elements to insert.
104 * @param srcStore The source store.
106 * @c beg and @c end define a range of container elements, with length
107 * @c len defined by the difference of the pointers divided by the
110 * The size of the container will be increased by @c len, with the elements
111 * starting at @c pos copied to @c pos+len.
113 * The contents of the source range will then be moved to our vector
114 * starting at @c pos. This will be done via move semantics if possible;
115 * otherwise, it will be done with a copy.
117 * Returns true if it is known that the vector's memory did not move,
120 template <class CONT, class VALLOC, class VELT, class ALLOC>
121 bool PackedLinkVVectorHolder<CONT, VALLOC, VELT, ALLOC>::insertMove
122 (size_t pos, void* src, size_t src_pos, size_t src_n,
125 bool ret = Base::insertMove (pos, src, src_pos, src_n, srcStore);
126 auto srcp = reinterpret_cast<element_type*> (src);
127 auto begp = srcp + src_pos;
128 auto endp = begp + src_n;
129 size_t n = std::distance (begp, endp);
130 vector_type& vec = this->vec();
131 const IAuxTypeVector* srcLv = srcStore.linkedVector (this->auxid());
132 typename Helper::const_DataLinkBase_span srcDLinks = Helper::getLinkBaseSpan (*srcLv);
134 for (size_t i = pos; i < pos+n; ++i) {
135 ret &= Helper::updateLinks (*m_linkedVec, vec[i].data(), vec[i].size(),
142 //*****************************************************************************
146 * @brief Constructor. Makes a new vector.
147 * @param auxid The auxid of the variable this vector represents.
148 * @param size Initial size of the new vector.
149 * @param capacity Initial capacity of the new vector.
150 * @param linkedVec Ownership of the linked vector.
152 template <class HOLDER>
153 PackedLinkVectorT<HOLDER>::PackedLinkVectorT (auxid_t auxid,
156 std::unique_ptr<IAuxTypeVector> linkedVec)
157 : Base (auxid, &m_vec, linkedVec.get(), false),
158 m_linkedVecHolder (std::move (linkedVec))
160 m_vec.reserve (capacity);
166 * @brief Copy constructor.
168 template <class HOLDER>
169 PackedLinkVectorT<HOLDER>::PackedLinkVectorT (const PackedLinkVectorT& other)
170 : Base (other.auxid(), &m_vec, false, false),
172 m_linkedVecHolder (other.m_linkedVec->clone())
174 Base::m_linkedVec = m_linkedVecHolder.get();
179 * @brief Move constructor.
181 template <class HOLDER>
182 PackedLinkVectorT<HOLDER>::PackedLinkVectorT (PackedLinkVectorT&& other)
183 : Base (other.auxid(), &m_vec, false, other.m_linkedVec),
184 m_vec (std::move (other.m_vec)),
185 m_linkedVecHolder (std::move (other.m_linkedVecHolder))
191 * @brief Make a copy of this vector.
193 template <class HOLDER>
195 std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::clone() const
197 return std::make_unique<PackedLinkVectorT> (*this);
202 * @brief Return ownership of the linked vector.
204 template <class HOLDER>
206 std::unique_ptr<IAuxTypeVector> PackedLinkVectorT<HOLDER>::linkedVector()
208 return std::move (m_linkedVecHolder);