File indexing completed on 2026-08-06 09:20:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef EVT_STREAM_INPUT_ITERATOR_HH
0022 #define EVT_STREAM_INPUT_ITERATOR_HH
0023
0024 #include "EvtGenBase/EvtStreamAdapter.hh"
0025
0026 #include <cstddef>
0027 #include <iterator>
0028
0029 using std::input_iterator_tag;
0030
0031
0032
0033
0034 template <class Point>
0035 class EvtStreamInputIterator {
0036 public:
0037 typedef input_iterator_tag iterator_category;
0038 typedef Point value_type;
0039 typedef ptrdiff_t difference_type;
0040 typedef const Point* pointer;
0041 typedef const Point& reference;
0042
0043 EvtStreamInputIterator() : _counter( 0 ) {}
0044
0045 EvtStreamInputIterator( const EvtStreamInputIterator& other ) :
0046 _counter( other._counter ? other._counter->clone() : 0 ),
0047 _currentValue( other._currentValue )
0048 {
0049 }
0050
0051 EvtStreamInputIterator( EvtStreamAdapter<Point>& counter ) :
0052 _counter( counter.clone() )
0053 {
0054 _currentValue = _counter->currentValue();
0055 }
0056
0057 ~EvtStreamInputIterator()
0058 {
0059 if ( _counter )
0060 delete _counter;
0061 }
0062
0063 reference operator*() const { return _currentValue; }
0064
0065 EvtStreamInputIterator& operator++()
0066 {
0067 _read();
0068 return *this;
0069 }
0070
0071 EvtStreamInputIterator operator++( int )
0072 {
0073 EvtStreamInputIterator tmp = *this;
0074 _read();
0075 return tmp;
0076 }
0077
0078 bool operator==( const EvtStreamInputIterator& other ) const
0079 {
0080
0081 return ( pastEnd() && other.pastEnd() );
0082 }
0083
0084 protected:
0085 EvtStreamAdapter<Point>* _counter;
0086 value_type _currentValue;
0087
0088 bool pastEnd() const
0089 {
0090 bool ret = true;
0091 if ( _counter )
0092 ret = _counter->pastEnd();
0093 return ret;
0094 }
0095
0096
0097
0098 void _read()
0099 {
0100 _counter->advance();
0101 _currentValue = _counter->currentValue();
0102 }
0103 };
0104
0105
0106
0107
0108 template <class Generator>
0109 EvtStreamInputIterator<typename Generator::result_type> iter( Generator gen,
0110 int N = 0 )
0111 {
0112 typedef typename Generator::result_type Point;
0113 EvtGenStreamAdapter<Point, Generator> counter( gen, N );
0114 return EvtStreamInputIterator<Point>( counter );
0115 }
0116
0117 #endif