BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Reconstruction/MdcPatRec/TrkBase/include/TrkBase/TrkHitOnTrkIter.h
Go to the documentation of this file.
1// "Adaptor" class which takes a class T, and presents a _guaranteed_ interface to T
2// This is done with templates instead of inheritance to avoid (virtual) function
3// call overhead, as these functions are going to be called from lots of loops,
4// and this way the interface gets inlined and (if everything goes well) no
5// overhead is incurred for using this iterator class compared to using
6// a 'raw' T instead... (but then you couldn't deal with different T's...)
7//
8// There is a similar example in Stroustroup, which turns an iterator into a 'checked'
9// iterator
10//
11// For the above to work, an implementation specific to 'T' has to be provided.
12// In order to allow 'T' to specify which implementation should be used, it should
13// provide a typename T::iterator_implementation that we can use here...
14//
15// To allow iterators over const TrkHitOnTrk and TrkHitOnTrk, 'T' should provide
16// a T::value_type which is either a const TrkHitOnTrk, or a TrkHitOnTrk
17//
18// BTW, the implementations tend to iterate over pointers to the valuetype,
19// and this class derefences the implementation to iterator over the valuetype instead...
20//
21#ifndef TRKHITONTRKITER_H
22#define TRKHITONTRKITER_H
23#include <cstddef>
24#include <iterator>
25
26// FIXME: only works on Linux: class TrkHitOnTrkIter : public
27// std::iterator_traits<TrkHitOnTrk *>
28// FIXME: only works on Linux: class TrkHitOnTrkIter : public
29// std::random_access_iterator<const TrkHitOnTrk, ptrdiff_t>
30// FIXME: only works on SunOS58: class TrkHitOnTrkIter : public
31// std::iterator<std::random_access_iterator_tag,TrkHitOnTrk>
32
33class TrkHitOnTrk;
34
35template <class T> class TrkHitOnTrkIter {
36 // by using T::iterator_value_type as our value_type, we can re-use the same
37 // code for a non-const iterator as a const iterator -- all that is needed
38 // is a slightly different 'traits' class T to be passed here; The underlying
39 // real iterator (the iterator_implementation) can be the same regardless of
40 // const or non-const...
41
42public:
43 typedef std::random_access_iterator_tag iterator_category;
44 typedef typename T::iterator_value_type value_type;
45 typedef ptrdiff_t difference_type;
48
49 typedef typename T::iterator_implementation iterator_implementation;
50
51 TrkHitOnTrkIter() : _i() {} // create an invalid iter...
52 TrkHitOnTrkIter( const TrkHitOnTrkIter<T>& i ) : _i( i._i ) {}
54
55 pointer get() const {
56 return *_i;
57 } // this function (together with * and ->) is one of the main
58 // reasons for this class:
59 // most (all?) underlying containers contain pointers to
60 // TrkHitOnTrk, and we need to double-dereference to
61 // create the illusion of something that iterates over
62 // (const) TrkHitOnTrk instead of (const) TrkHitOnTrk*
63
64 pointer operator->() const { return this->get(); }
65 reference operator*() const { return *this->get(); }
66
67 // next: forward all usual random access iterator operations
68 // to the underlying actual implementation...
69
71 _i -= i;
72 return *this;
73 }
75 _i += i;
76 return *this;
77 }
78
81 x -= i;
82 return x;
83 }
86 x += i;
87 return x;
88 }
89
91 --_i;
92 return *this;
93 } // prefix --
95 ++_i;
96 return *this;
97 } // prefix ++
98
100 TrkHitOnTrkIter<T> x( _i );
101 --_i;
102 return x;
103 } // postfix --
105 TrkHitOnTrkIter<T> x( _i );
106 ++_i;
107 return x;
108 } // postfix ++
109
110 ptrdiff_t operator-( const TrkHitOnTrkIter<T>& i ) const { return _i - i._i; }
111 bool operator==( const TrkHitOnTrkIter<T>& i ) const { return _i == i._i; }
112 bool operator!=( const TrkHitOnTrkIter<T>& i ) const { return !operator==( i ); }
113 bool operator<( const TrkHitOnTrkIter<T>& i ) const { return _i < i._i; }
114 bool operator>=( const TrkHitOnTrkIter<T>& i ) const { return !operator<( i ); }
115 bool operator>( const TrkHitOnTrkIter<T>& i ) const { return _i > i._i; }
116 bool operator<=( const TrkHitOnTrkIter<T>& i ) const { return !operator>( i ); }
117
118private:
120};
121#endif
Double_t x[10]
ptrdiff_t operator-(const TrkHitOnTrkIter< T > &i) const