BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtStreamInputIterator.hh
Go to the documentation of this file.
1/*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
3 * Package: EvtGenBase
4 * File: $Id: EvtStreamInputIterator.hh,v 1.2 2015/04/07 07:39:37 pingrg Exp $
5 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
6 *
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
9
10// Adapters are used to convert various types of input streams
11// into an iteratable interface.
12
13#ifndef EVT_STREAM_INPUT_ITERATOR_HH
14#define EVT_STREAM_INPUT_ITERATOR_HH
15
16#include "EvtStreamAdapter.hh"
17#include <iterator>
18using std::input_iterator_tag;
19
20template <class Point> class EvtStreamInputIterator {
21public:
22 typedef input_iterator_tag iterator_category;
23 typedef Point value_type;
24 // typedef ptrdiff_t difference_type;
25 typedef const Point* pointer;
26 typedef const Point& reference;
27
29
31 : _counter( other._counter ? other._counter->clone() : 0 )
32 , _currentValue( other._currentValue ) {}
33
34 EvtStreamInputIterator( EvtStreamAdapter<Point>& counter ) : _counter( counter.clone() ) {
35 _currentValue = _counter->currentValue();
36 }
37
39 if ( _counter ) delete _counter;
40 }
41
42 reference operator*() const { return _currentValue; }
43
45 _read();
46 return *this;
47 }
48
50 EvtStreamInputIterator tmp = *this;
51 _read();
52 return tmp;
53 }
54
55 bool operator==( const EvtStreamInputIterator& other ) const {
56 // Equality is only defined for two past the end iterators
57 return ( pastEnd() && other.pastEnd() );
58 }
59
60protected:
63
64 bool pastEnd() const {
65 bool ret = true;
66 if ( _counter ) ret = _counter->pastEnd();
67 return ret;
68 }
69
70 // Advances the iterator
71
72 void _read() {
73
74 _counter->advance();
75 _currentValue = _counter->currentValue();
76 }
77};
78
79// For adaptable generators these shorthand functions can be used
80// to construct iterators.
81
82template <class Generator>
84 typedef typename Generator::result_type Point;
86 return EvtStreamInputIterator<Point>( counter );
87}
88
89#endif
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
EvtStreamInputIterator operator++(int)
EvtStreamInputIterator(const EvtStreamInputIterator &other)
bool operator==(const EvtStreamInputIterator &other) const
input_iterator_tag iterator_category
EvtStreamAdapter< Point > * _counter
EvtStreamInputIterator & operator++()
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)