ATLAS Offline Software
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  */
20 template <class DV>
21 inline
22 ViewVector<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  */
40 template <class DV>
41 inline
42 ViewVector<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  */
56 template <class DV>
57 template <class InputIterator>
58 inline
59 ViewVector<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  */
72 template <class DV>
73 inline
74 ViewVector<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  */
87 template <class DV>
88 inline
89 ViewVector<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  */
102 template <class DV>
103 inline
104 ViewVector<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  */
116 template <class DV>
117 inline
118 ViewVector<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  */
137 template <class DV>
138 inline
139 ViewVector<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  */
154 template <class DV>
155 inline
156 ViewVector<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  */
174 template <class DV>
175 inline
176 ViewVector<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  */
193 template <class DV>
194 inline
195 ViewVector<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  */
209 template <class DV>
210 inline
211 void 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  */
221 template <class DV>
222 inline
223 void ViewVector<DV>::toPersistent()
224 {
225  doToPersistent (*static_cast<DV*>(this));
226 }
227 
228 
229 /**
230  * @brief Convert the vector to transient form.
231  */
232 template <class DV>
233 inline
234 void 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  */
248 template <class DV>
249 inline
250 void 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  */
262 template <class DV>
263 void ViewVector<DV>::registerBaseInit()
264 {
265 #ifndef XAOD_STANDALONE
266  static const SG::RegisterBaseInit<ViewVector> rbi;
267 #endif
268 }