ATLAS Offline Software
Loading...
Searching...
No Matches
ViewVector.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
6/**
7 * @file AthContainers/ViewVector.icc
8 * @author scott snyder <snyder@bnl.gov>
9 * @date Jan, 2016
10 * @brief Identify view containers to be made persistent.
11 */
12
13
14/**
15 * @brief Default constructor.
16 * @param ownPolicy The ownership mode for the container.
17 * Must be @c SG::VIEW_ELEMENTS.
18 * (Argument present only for interface compatibility.)
19 */
20template <class DV>
21inline
22ViewVector<DV>::ViewVector(SG::OwnershipPolicy ownPolicy /*= SG::VIEW_ELEMENTS*/)
23 : DV (SG::VIEW_ELEMENTS)
24{
25 if (ownPolicy != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
26 registerBaseInit();
27}
28
29
30/**
31 * @brief Sized constructor.
32 * @param n The size of the container.
33 * @param ownPolicy The ownership mode for the container.
34 * Must be @c SG::VIEW_ELEMENTS.
35 * (Argument present only for interface compatibility.)
36 *
37 * Note that unlike the standard vector constructor, you can't specify
38 * an initial value here. The container will be initialized with 0's.
39 */
40template <class DV>
41inline
42ViewVector<DV>::ViewVector(size_type n,
43 SG::OwnershipPolicy ownPolicy /*= SG::VIEW_ELEMENTS*/)
44 : DV (n, SG::VIEW_ELEMENTS)
45{
46 if (ownPolicy != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
47 registerBaseInit();
48}
49
50
51/**
52 * @brief Constructor from iterators.
53 * @param first The start of the range to put in the new container.
54 * @param last The end of the range to put in the new container.
55 */
56template <class DV>
57template <class InputIterator>
58inline
59ViewVector<DV>::ViewVector(InputIterator first, InputIterator last)
60 : DV (first, last, SG::VIEW_ELEMENTS)
61{
62 registerBaseInit();
63}
64
65
66/**
67 * @brief Move constructor.
68 * @param rhs The container from which to move.
69 *
70 * Any auxiliary data will be moved along with the container contents.
71 */
72template <class DV>
73inline
74ViewVector<DV>::ViewVector (ViewVector&& rhs)
75{
76 // Redundant, but just to check for problems.
77 if (rhs.ownPolicy() != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
78 DV::operator= (std::move (rhs));
79 registerBaseInit();
80}
81
82
83/**
84 * @brief Constructor from base vector..
85 * @param rhs The container from which to copy.
86 */
87template <class DV>
88inline
89ViewVector<DV>::ViewVector (const DV& rhs)
90 : DV(rhs)
91{
92 registerBaseInit();
93}
94
95
96/**
97 * @brief Move constructor from base vector.
98 * @param rhs The container from which to copy. Must be a view container.
99 *
100 * Any auxiliary data will be moved along with the container contents.
101 */
102template <class DV>
103inline
104ViewVector<DV>::ViewVector (DV&& rhs)
105 : DV(std::move(rhs))
106{
107 if (this->ownPolicy() != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
108 registerBaseInit();
109}
110
111
112/**
113 * @brief Constructor from an initializer list.
114 * @param l An initializer list.
115 */
116template <class DV>
117inline
118ViewVector<DV>::ViewVector(std::initializer_list<value_type> l)
119 : DV (l, SG::VIEW_ELEMENTS)
120{
121 registerBaseInit();
122}
123
124
125/**
126 * @brief Assignment operator.
127 * @param rhs The DataVector from which to assign.
128 * @return This object.
129 *
130 * This is a `shallow' copy; after the completion of this, the DataVector
131 * will not own its elements. Any elements it owned prior to this call
132 * will be released.
133 *
134 * Note: this method may only be called using the most derived
135 * @c DataVector in the hierarchy.
136 */
137template <class DV>
138inline
139ViewVector<DV>& ViewVector<DV>::operator= (const DV& rhs)
140{
141 if (this != &rhs) {
142 DV::operator= (rhs);
143 }
144 return *this;
145}
146
147
148/**
149 * @brief Move assignment.
150 * @param rhs The container from which to move.
151 *
152 * Any auxiliary data will be moved along with the container contents.
153 */
154template <class DV>
155inline
156ViewVector<DV>& ViewVector<DV>::operator= (ViewVector&& rhs)
157{
158 if (this != &rhs) {
159 // Redundant but good to check anyway.
160 if (this->ownPolicy() != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
161 DV::operator= (std::move (rhs));
162 }
163 return *this;
164}
165
166
167/**
168 * @brief Move assignment from base vector.
169 * @param rhs The container from which to move.
170 * Must be a view vector.
171 *
172 * Any auxiliary data will be moved along with the container contents.
173 */
174template <class DV>
175inline
176ViewVector<DV>& ViewVector<DV>::operator= (DV&& rhs)
177{
178 if (this != &rhs) {
179 if (rhs.ownPolicy() != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
180 DV::operator= (std::move (rhs));
181 }
182 return *this;
183}
184
185
186/**
187 * @brief Assignment operator, from an initializer list.
188 * @param l An initializer list.
189 * @return This object.
190 *
191 * This is equivalent to @c assign.
192 */
193template <class DV>
194inline
195ViewVector<DV>& ViewVector<DV>::operator= (std::initializer_list<value_type> l)
196{
197 DV::operator= (l);
198 return *this;
199}
200
201
202/**
203 * @fn void clear
204 * @brief Erase all the elements in the collection.
205 * @param ownPolicy The new ownership policy of the container.
206 * Must be SG::VIEW_ELEMENTS.
207 * (Argument present only for interface compatibility.)
208 */
209template <class DV>
210inline
211void ViewVector<DV>::clear (SG::OwnershipPolicy ownPolicy)
212{
213 if (ownPolicy != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
214 DV::clear (SG::VIEW_ELEMENTS);
215}
216
217
218/**
219 * @brief Convert the vector to persistent form.
220 */
221template <class DV>
222inline
223void ViewVector<DV>::toPersistent()
224{
225 doToPersistent (*static_cast<DV*>(this));
226}
227
228
229/**
230 * @brief Convert the vector to transient form.
231 */
232template <class DV>
233inline
234void ViewVector<DV>::toTransient()
235{
236 doToTransient (*static_cast<DV*>(this));
237}
238
239
240/**
241 * @fn void clear
242 * @brief Erase all the elements in the collection.
243 * @param ownPolicy The new ownership policy of the container.
244 * Must be SG::VIEW_ELEMENTS.
245 * (Argument present only for interface compatibility.)
246 * @param trackIndices The index tracking policy.
247 */
248template <class DV>
249inline
250void ViewVector<DV>::clear (SG::OwnershipPolicy ownPolicy,
251 SG::IndexTrackingPolicy trackIndices)
252{
253 if (ownPolicy != SG::VIEW_ELEMENTS) SG::throwExcViewVectorNotView();
254 DV::clear (SG::VIEW_ELEMENTS, trackIndices);
255}
256
257
258/**
259 * @brief Helper to ensure that the inheritance information for this class
260 * gets initialized.
261 */
262template <class DV>
263void ViewVector<DV>::registerBaseInit()
264{
265#ifndef XAOD_STANDALONE
266 static const SG::RegisterBaseInit<ViewVector> rbi;
267#endif
268}