1 // Dear emacs, this is -*- c++ -*-
3 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 #ifndef ATHLINKS_ELEMENTLINKVECTOR_ICC
6 #define ATHLINKS_ELEMENTLINKVECTOR_ICC
11 ////////////////////////////////////////////////////////////////////////////////
13 // Implementation of the different constructors
16 template< class CONTAINER >
17 ElementLinkVector< CONTAINER >::ElementLinkVector()
18 : ElementLinkVectorBase(), m_elVec() {
22 template< class CONTAINER >
23 ElementLinkVector< CONTAINER >::ElementLinkVector( size_type n,
24 const ElemLink& link )
25 : ElementLinkVectorBase(), m_elVec( n, link ) {
27 // Create the persistent information:
31 template< class CONTAINER >
32 ElementLinkVector< CONTAINER >::ElementLinkVector( const ElemLinkVec& parent )
33 : ElementLinkVectorBase( parent ), m_elVec( parent.m_elVec ) {
38 ////////////////////////////////////////////////////////////////////////////////
40 template< class CONTAINER >
41 typename ElementLinkVector< CONTAINER >::ElemLinkVec&
42 ElementLinkVector< CONTAINER >::operator=( const ElemLinkVec& rhs ) {
44 // Copy the contents of the base class:
45 ElementLinkVectorBase::operator=( rhs );
47 // Copy the member variable(s):
48 m_elVec = rhs.m_elVec;
50 // Return this same object:
54 template< class CONTAINER >
55 bool ElementLinkVector< CONTAINER >::
56 operator==( const ElementLinkVector& rhs ) const {
58 if( m_elVec.size() != rhs.m_elVec.size() ) {
61 for( std::size_t i = 0; i < m_elVec.size(); ++i ) {
62 if( m_elVec[ i ] != rhs.m_elVec[ i ] ) {
69 template< class CONTAINER >
70 bool ElementLinkVector< CONTAINER >::
71 operator!=( const ElementLinkVector& rhs ) const {
73 return ( ! ( *this == rhs ) );
76 ////////////////////////////////////////////////////////////////////////////////
78 // Implementation of the vector capacity functions
81 template< class CONTAINER >
82 void ElementLinkVector< CONTAINER >::resize( size_type sz,
83 const ElemLink& link ) {
85 // Resize the transient vector:
86 m_elVec.resize( sz, link );
88 // Now re-create the persistent information:
96 ////////////////////////////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////////////////////////////
100 // Implementation of the vector modifier functions
103 template< class CONTAINER >
104 void ElementLinkVector< CONTAINER >::push_back( const ElemLink& el ) {
106 // Add the new transient object:
107 m_elVec.push_back( el );
109 // Add the persistent info about it as well:
110 m_persKeys.push_back( el.persKey() );
111 m_persIndices.push_back( el.persIndex() );
113 // Return gracefully:
117 template< class CONTAINER >
118 void ElementLinkVector< CONTAINER >::pop_back() {
120 // Remove the last transient object:
123 // Remove the last persistent objects:
124 m_persKeys.pop_back();
125 m_persIndices.pop_back();
127 // Return gracefully:
131 template< class CONTAINER >
132 typename ElementLinkVector< CONTAINER >::iterator
133 ElementLinkVector< CONTAINER >::erase( iterator position ) {
135 // Do the deed, and remember the iterator:
136 iterator result = m_elVec.erase( position );
138 // It may be more performant later on to put in dedicated code
139 // here, but for now let's do the simplest thing:
142 // Return the cached iterator:
146 template< class CONTAINER >
147 typename ElementLinkVector< CONTAINER >::iterator
148 ElementLinkVector< CONTAINER >::erase( iterator first, iterator last ) {
150 // Do the deed, and remember the iterator:
151 iterator result = m_elVec.erase( first, last );
153 // It may be more performant later on to put in dedicated code
154 // here, but for now let's do the simplest thing:
157 // Return the cached iterator:
161 template< class CONTAINER >
162 void ElementLinkVector< CONTAINER >::swap( ElemLinkVec& vec ) {
164 // Swap the transient variable:
165 m_elVec.swap( vec.m_elVec );
167 // Swap the persistent variables:
168 m_persKeys.swap( vec.m_persKeys );
169 m_persIndices.swap( vec.m_persIndices );
171 // Return gracefully:
175 template< class CONTAINER >
176 template< class InputIterator >
177 void ElementLinkVector< CONTAINER >::assign( InputIterator first,
178 InputIterator last ) {
180 // Achieve the result using other functions of the class:
182 insert( begin(), first, last );
185 template< class CONTAINER >
186 void ElementLinkVector< CONTAINER >::assign( size_type n,
187 const ElemLink& link ) {
189 // Achieve the result using other functions of the class:
191 insert( begin(), n, link );
194 template< class CONTAINER >
195 typename ElementLinkVector< CONTAINER >::iterator
196 ElementLinkVector< CONTAINER >::insert( iterator position,
197 const ElemLink& link ) {
199 // Insert the new link:
200 iterator result = m_elVec.insert( position, link );
202 // It may be more performant later on to put in dedicated code
203 // here, but for now let's do the simplest thing:
206 // Return the cached iterator:
210 template< class CONTAINER >
211 void ElementLinkVector< CONTAINER >::insert( iterator position,
213 const ElemLink& link ) {
216 m_elVec.insert( position, n, link );
218 // It may be more performant later on to put in dedicated code
219 // here, but for now let's do the simplest thing:
223 template< class CONTAINER >
224 void ElementLinkVector< CONTAINER >::clear() {
226 // Simply clear all variables:
229 m_persIndices.clear();
231 // Return gracefully:
236 ////////////////////////////////////////////////////////////////////////////////
238 template< class CONTAINER >
239 bool ElementLinkVector< CONTAINER >::toTransient() {
241 // A little sanity check:
242 assert( m_persKeys.size() == m_persIndices.size() );
244 // Re-create the transient variables based on the
247 m_elVec.reserve( m_persKeys.size() );
248 for( size_t i = 0; i < m_persKeys.size(); ++i ) {
249 m_elVec.push_back( ElemLink( m_persKeys[ i ], m_persIndices[ i ] ) );
252 // Return a dummy value:
256 /// In a few cases the simplest way of syncronising the transient and
257 /// persistent data of the object is to simply re-create the persistent
258 /// data from scratch. This function does this.
260 /// @returns <code>true</code> in case of success, and <code>false</code>
261 /// in case of failure
263 template< class CONTAINER >
264 bool ElementLinkVector< CONTAINER >::toPersistent() {
266 // First, clear the current persistent info:
268 m_persIndices.clear();
270 // Loop over all the links in this container:
271 iterator p_itr = begin();
272 iterator p_end = end();
273 for( ; p_itr != p_end; ++p_itr ) {
275 // Ask the link to make itself persistifiable. (Shouldn't do anything
276 // actually, but maybe we'll need to do something special in
277 // ElementLink::toPersistent() at one point...)
278 if( ! p_itr->toPersistent() ) return false;
280 // Copy the link's persistent data into the base class's variables:
281 m_persKeys.push_back( p_itr->persKey() );
282 m_persIndices.push_back( p_itr->persIndex() );
285 // Return gracefully:
289 #endif // ATHLINKS_ELEMENTLINKVECTOR_ICC