BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/DecayChain/include/DecayChain/Iterator/PartialCandidateItr.h
Go to the documentation of this file.
1#ifndef DCHAIN_PARTIALCANDIDATEITR_H
2#define DCHAIN_PARTIALCANDIDATEITR_H
3// -*- C++ -*-
4//
5// Package: DChain
6// Module: PartialCandidateItr
7//
8// Description: Iterator through a part of a LabeledCandidateList.
9//
10// Usage:
11// <usage>
12//
13// Author: Simon Patton
14// Created: Wed Sep 11 21:51:25 EDT 1996
15// $Id: PartialCandidateItr.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $
16//
17// Revision history
18//
19// $Log: PartialCandidateItr.h,v $
20// Revision 1.1.1.1 2009/03/03 06:06:56 maqm
21// first import of DecayChain
22//
23// Revision 1.1 2006/01/11 20:28:18 cdj
24// massive class renaming, addition of [] for selection and unit tests
25//
26//
27
28// system include files
29#include <iterator>
30
31// user include files
32#include "DecayChain/Element/LabeledCandidate.h" // equal function
33#include "DecayChain/Element/conjugation.h" // enumarator
34#include "DecayChain/Iterator/candidateitr.h" // distance
35// #include "DecayChain/List/IndexedLabeledCandidates.h" // labeledStonceClass()
36
37// forward declarations
38
39template <class CandidateClass> class IndexedLabeledCandidates;
40
41namespace dchain {
42
43 template <class CandidateClass> class LabeledCandidate;
44 template <class CandidateClass> class LabeledCandidateList;
45
46 template <class CandidateClass> class PartialCandidateItr {
47 // friend classses and functions
48 friend class LabeledCandidateList<CandidateClass>;
49
50 public:
51 // constants, enums and typedefs
52 // typedef int distance ;
58
59 typedef std::bidirectional_iterator_tag iterator_category;
60
61 // Constructors and destructor
62 PartialCandidateItr(); // used by CombinatoricList to build array
65
66 // assignment operator(s)
69
70 // member functions
75
76 // const member functions
78 bool operator==( const PartialCandidateItr<CandidateClass>& aOtherItr ) const;
79 bool operator!=( const PartialCandidateItr<CandidateClass>& aOtherItr ) const;
80
81 // static member functions
82
83 protected:
84 // Constructors and destructor
86 const size_type aIndex, const conjugation::Label aLabel );
87
88 // protected member functions
89
90 // protected const member functions
94
95 private:
96 // Constructors and destructor
97
98 // private member functions
99
100 // private const member functions
101
102 // data members
103 IndexedLabeledCandidates<CandidateClass>* m_indexedCandidates;
104 size_type m_index;
105 conjugation::Label m_label;
106
107 // static data members
108 };
109
110 // inline function definitions
111
112 // user include files
113
114 //
115 // forward definitions of inline functions
116 //
117
118 template <class CandidateClass>
121 return ( m_indexedCandidates );
122 }
123
124 template <class CandidateClass>
127 return ( m_index );
128 }
129
130 template <class CandidateClass>
132 return ( m_label );
133 }
134
135 //
136 // constructors and destructor
137 //
138
139 template <class CandidateClass>
141
142 template <class CandidateClass>
144 const PartialCandidateItr<CandidateClass>& aOtherItr )
145 : m_indexedCandidates( aOtherItr.indexedCandidates() )
146 , m_index( aOtherItr.index() )
147 , m_label( aOtherItr.label() ) {}
148
149 template <class CandidateClass>
151 const IndexedLabeledCandidates<CandidateClass>* aList, const size_type aIndex,
152 const conjugation::Label aLabel )
153 : // cast away const as const_iterator can be assocciated with a non-const list,
154 // but only const lists use this constructor
155 m_indexedCandidates( (IndexedLabeledCandidates<CandidateClass>*)aList )
156 , m_index( aIndex )
157 , m_label( aLabel ) {
158 // move to first entry with correct label
159 if ( ( m_index < size_type( ( *m_indexedCandidates ).size() ) ) &&
160 ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) != m_label ) )
161 { operator++(); }
162 }
163
164 //
165 // assignment operators
166 //
167
168 template <class CandidateClass>
171 const PartialCandidateItr<CandidateClass>& aOtherItr ) {
172 m_indexedCandidates = aOtherItr.indexedCandidates();
173 m_index = aOtherItr.index();
174 m_label = aOtherItr.label();
175 return ( *this );
176 }
177
178 //
179 // member functions
180 //
181
182 template <class CandidateClass>
185 ++m_index;
186 // This while loop find next match to label.
187 // The order is done for efficiency reasons. It is more likely a label
188 // will match than the end of the list has been reached. However this
189 // will can cause an access to an uninitiallized location, but the
190 // loop will still terminate correctly.
191 // update: the efficiency doesn't matter but reading invalid memory
192 // makes our automated memory checkers have fits
193 while ( ( m_index < size_type( ( *m_indexedCandidates ).size() ) &&
194 ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) != m_label ) ) )
195 { ++m_index; }
196 return ( *this );
197 }
198
199 template <class CandidateClass>
203 ++m_index;
204 // This while loop find next match to label.
205 // The order is done for efficiency reasons. It is more likely a label
206 // will match than the end of the list has been reached. However this
207 // will can cause an access to an uninitiallized location, but the
208 // loop will still terminate correctly.
209 while ( ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) != m_label ) &&
210 ( m_index < size_type( ( *m_indexedCandidates ).size() ) ) )
211 { ++m_index; }
212 return ( tmp );
213 }
214
215 template <class CandidateClass>
218 // As the index is 'unsigned' it should not go below zero. This behavior is completely
219 // consistent with the STL reverse_iterator adaptor. (See pp254 of Musser & Saini)
220 //
221 if ( 0 != m_index ) { --m_index; }
222 // This while loop find next match to label.
223 // The order is done for efficiency reasons. It is more likely a label
224 // will match than the end of the list has been reached. However this
225 // will can cause an access to an uninitiallized location, but the
226 // loop will still terminate correctly.
227 while ( ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) != m_label ) &&
228 ( m_index != 0 ) )
229 { --m_index; }
230 return ( *this );
231 }
232
233 template <class CandidateClass>
237 // As the index is 'unsigned' it should not go below zero. This behavior is completely
238 // consistent with the STL reverse_iterator adaptor. (See pp254 of Musser & Saini)
239 //
240 if ( 0 != m_index ) { --m_index; }
241 // This while loop find next match to label.
242 // The order is done for efficiency reasons. It is more likely a label
243 // will match than the end of the list has been reached. However this
244 // will can cause an access to an uninitiallized location, but the
245 // loop will still terminate correctly.
246 while ( ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) != m_label ) &&
247 ( m_index != 0 ) )
248 { --m_index; }
249 return ( tmp );
250 }
251
252 //
253 // const member functions
254 //
255
256 template <class CandidateClass>
259 return ( ( *m_indexedCandidates ).labeledCandidateClass( m_index ) );
260 }
261
262 template <class CandidateClass>
264 const PartialCandidateItr<CandidateClass>& aOtherItr ) const {
265 // There needs to be a final test on the label as itrs with two different labels
266 // have the same values for the past-the-end value
267 return ( ( m_index == aOtherItr.index() ) &&
268 ( m_indexedCandidates == aOtherItr.indexedCandidates() ) &&
269 ( m_label == aOtherItr.label() ) );
270 }
271
272 template <class CandidateClass>
274 const PartialCandidateItr<CandidateClass>& aOtherItr ) const {
275 // There needs to be a final test on the label as itrs with two different labels
276 // have the same values for the past-the-end value
277 return ( ( m_index != aOtherItr.index() ) ||
278 ( m_indexedCandidates != aOtherItr.indexedCandidates() ) ||
279 ( m_label != aOtherItr.label() ) );
280 }
281} // namespace dchain
282
283#endif /* DCHAIN_PARTIALCANDIDATEITR_H */
const PartialCandidateItr< CandidateClass > & operator=(const PartialCandidateItr< CandidateClass > &aOtherItr)
bool operator==(const PartialCandidateItr< CandidateClass > &aOtherItr) const
bool operator!=(const PartialCandidateItr< CandidateClass > &aOtherItr) const
IndexedLabeledCandidates< CandidateClass > * indexedCandidates() const