BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
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/conjugation.h" // enumarator
33#include "DecayChain/Iterator/candidateitr.h" // distance
34#include "DecayChain/Element/LabeledCandidate.h" // equal function
35//#include "DecayChain/List/IndexedLabeledCandidates.h" // labeledStonceClass()
36
37// forward declarations
38
39template < class CandidateClass > class IndexedLabeledCandidates ;
40
41namespace dchain {
42
43template < class CandidateClass > class LabeledCandidate ;
44template < class CandidateClass > class LabeledCandidateList ;
45
46template < class CandidateClass >
48{
49 // friend classses and functions
50 friend class LabeledCandidateList< CandidateClass > ;
51
52 public:
53 // constants, enums and typedefs
54 // typedef int distance ;
60
61 typedef std::bidirectional_iterator_tag iterator_category;
62
63
64 // Constructors and destructor
65 PartialCandidateItr() ; // used by CombinatoricList to build array
68
69 // assignment operator(s)
71
72 // member functions
77
78 // const member functions
80 bool operator==( const PartialCandidateItr< CandidateClass >& aOtherItr ) const ;
81 bool operator!=( const PartialCandidateItr< CandidateClass >& aOtherItr ) const ;
82
83 // static member functions
84
85 protected:
86 // Constructors and destructor
88 const size_type aIndex ,
89 const conjugation::Label aLabel ) ;
90
91 // protected member functions
92
93 // protected const member functions
95 size_type index() const ;
97
98 private:
99 // Constructors and destructor
100
101 // private member functions
102
103 // private const member functions
104
105 // data members
106 IndexedLabeledCandidates< CandidateClass >* m_indexedCandidates ;
107 size_type m_index ;
108 conjugation::Label m_label ;
109
110 // static data members
111
112} ;
113
114// inline function definitions
115
116// user include files
117
118//
119// forward definitions of inline functions
120//
121
122template < class CandidateClass >
123inline
125{
126 return ( m_indexedCandidates ) ;
127}
128
129template < class CandidateClass >
130inline
133{
134 return ( m_index ) ;
135}
136
137template < class CandidateClass >
138inline
140{
141 return ( m_label ) ;
142}
143
144//
145// constructors and destructor
146//
147
148template < class CandidateClass >
149inline
151{
152}
153
154template < class CandidateClass >
155inline
157 m_indexedCandidates( aOtherItr.indexedCandidates() ) ,
158 m_index( aOtherItr.index() ) ,
159 m_label( aOtherItr.label() )
160{
161}
162
163template < class CandidateClass >
164inline
166 const size_type aIndex ,
167 const conjugation::Label aLabel ) :
168 // cast away const as const_iterator can be assocciated with a non-const list,
169 // but only const lists use this constructor
170 m_indexedCandidates( (IndexedLabeledCandidates< CandidateClass >*)aList ) ,
171 m_index( aIndex ) ,
172 m_label( aLabel )
173{
174 // move to first entry with correct label
175 if ( ( m_index < size_type( (*m_indexedCandidates).size() ) ) &&
176 ( (*m_indexedCandidates).labeledCandidateClass( m_index ) != m_label )
177 ) {
178 operator++() ;
179 }
180}
181
182//
183// assignment operators
184//
185
186template < class CandidateClass >
187inline
189{
190 m_indexedCandidates = aOtherItr.indexedCandidates() ;
191 m_index = aOtherItr.index() ;
192 m_label = aOtherItr.label() ;
193 return ( *this ) ;
194}
195
196//
197// member functions
198//
199
200template < class CandidateClass >
201inline
203{
204 ++m_index ;
205 // This while loop find next match to label.
206 // The order is done for efficiency reasons. It is more likely a label
207 // will match than the end of the list has been reached. However this
208 // will can cause an access to an uninitiallized location, but the
209 // loop will still terminate correctly.
210 // update: the efficiency doesn't matter but reading invalid memory
211 // makes our automated memory checkers have fits
212 while (
213 ( m_index < size_type( (*m_indexedCandidates).size() ) &&
214 ( (*m_indexedCandidates).labeledCandidateClass( m_index ) != m_label )
215 ) ) {
216 ++m_index ;
217 }
218 return ( *this ) ;
219}
220
221template < class CandidateClass >
222inline
224{
226 ++m_index ;
227 // This while loop find next match to label.
228 // The order is done for efficiency reasons. It is more likely a label
229 // will match than the end of the list has been reached. However this
230 // will can cause an access to an uninitiallized location, but the
231 // loop will still terminate correctly.
232 while (
233 ( (*m_indexedCandidates).labeledCandidateClass( m_index ) != m_label ) &&
234 ( m_index < size_type( (*m_indexedCandidates).size() ) ) ) {
235 ++m_index ;
236 }
237 return ( tmp ) ;
238}
239
240template < class CandidateClass >
241inline
243{
244 // As the index is 'unsigned' it should not go below zero. This behavior is completely
245 // consistent with the STL reverse_iterator adaptor. (See pp254 of Musser & Saini)
246 //
247 if ( 0 != m_index ) {
248 --m_index ;
249 }
250 // This while loop find next match to label.
251 // The order is done for efficiency reasons. It is more likely a label
252 // will match than the end of the list has been reached. However this
253 // will can cause an access to an uninitiallized location, but the
254 // loop will still terminate correctly.
255 while (
256 ( (*m_indexedCandidates).labeledCandidateClass( m_index ) != m_label ) &&
257 ( m_index != 0 ) ) {
258 --m_index ;
259 }
260 return ( *this ) ;
261}
262
263template < class CandidateClass >
264inline
266{
268 // As the index is 'unsigned' it should not go below zero. This behavior is completely
269 // consistent with the STL reverse_iterator adaptor. (See pp254 of Musser & Saini)
270 //
271 if ( 0 != m_index ) {
272 --m_index ;
273 }
274 // This while loop find next match to label.
275 // The order is done for efficiency reasons. It is more likely a label
276 // will match than the end of the list has been reached. However this
277 // will can cause an access to an uninitiallized location, but the
278 // loop will still terminate correctly.
279 while (
280 ( (*m_indexedCandidates).labeledCandidateClass( m_index ) != m_label ) &&
281 ( m_index != 0 ) ) {
282 --m_index ;
283 }
284 return ( tmp ) ;
285}
286
287//
288// const member functions
289//
290
291template < class CandidateClass >
292inline
294{
295 return ( (*m_indexedCandidates).labeledCandidateClass( m_index ) ) ;
296}
297
298template < class CandidateClass >
299inline
301{
302 // There needs to be a final test on the label as itrs with two different labels
303 // have the same values for the past-the-end value
304 return ( ( m_index == aOtherItr.index() ) &&
305 ( m_indexedCandidates == aOtherItr.indexedCandidates() ) &&
306 ( m_label == aOtherItr.label() ) ) ;
307}
308
309template < class CandidateClass >
310inline
312{
313 // There needs to be a final test on the label as itrs with two different labels
314 // have the same values for the past-the-end value
315 return ( ( m_index != aOtherItr.index() ) ||
316 ( m_indexedCandidates != aOtherItr.indexedCandidates() ) ||
317 ( m_label != aOtherItr.label() ) ) ;
318}
319}
320
321#endif /* DCHAIN_PARTIALCANDIDATEITR_H */
const PartialCandidateItr< CandidateClass > & operator=(const PartialCandidateItr< CandidateClass > &aOtherItr)
const LabeledCandidate< CandidateClass > & operator*() const
std::bidirectional_iterator_tag iterator_category
bool operator==(const PartialCandidateItr< CandidateClass > &aOtherItr) const
PartialCandidateItr< CandidateClass > & operator--()
PartialCandidateItr< CandidateClass > operator++(int)
conjugation::Label label() const
dchain::candidateitr::size_type size_type
PartialCandidateItr(const PartialCandidateItr< CandidateClass > &aOtherItr)
LabeledCandidate< CandidateClass > value_type
dchain::candidateitr::difference_type difference_type
bool operator!=(const PartialCandidateItr< CandidateClass > &aOtherItr) const
IndexedLabeledCandidates< CandidateClass > * indexedCandidates() const
PartialCandidateItr(const IndexedLabeledCandidates< CandidateClass > *aList, const size_type aIndex, const conjugation::Label aLabel)
PartialCandidateItr< CandidateClass > & operator++()
PartialCandidateItr< CandidateClass > operator--(int)
unsigned int size_type
Definition: candidateitr.h:36