BOSS 7.0.3
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, [email protected], 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
17#include <iterator>
18using std::input_iterator_tag;
19
20template <class Point>
22public:
23
24 typedef input_iterator_tag iterator_category;
25 typedef Point value_type;
26 //typedef ptrdiff_t difference_type;
27 typedef const Point* pointer;
28 typedef const Point& reference;
29
31 : _counter(0)
32 {}
33
35 : _counter(other._counter ? other._counter->clone() : 0),
37 {}
38
40 : _counter(counter.clone())
41 {
42 _currentValue = _counter->currentValue();
43 }
44
46 {
47 if(_counter) delete _counter;
48 }
49
51 {
52 return _currentValue;
53 }
54
56 {
57 _read();
58 return *this;
59 }
60
62 {
63 EvtStreamInputIterator tmp = *this;
64 _read();
65 return tmp;
66 }
67
68 bool operator==(const EvtStreamInputIterator& other) const
69 {
70 // Equality is only defined for two past the end iterators
71 return (pastEnd() && other.pastEnd());
72 }
73
74protected:
75
78
79 bool pastEnd() const
80 {
81 bool ret = true;
82 if(_counter) ret = _counter->pastEnd();
83 return ret;
84 }
85
86 // Advances the iterator
87
88 void _read() {
89
90 _counter->advance();
91 _currentValue = _counter->currentValue();
92 }
93};
94
95
96// For adaptable generators these shorthand functions can be used
97// to construct iterators.
98
99template <class Generator>
101{
102 typedef typename Generator::result_type Point;
104 return EvtStreamInputIterator<Point>(counter);
105}
106
107
108#endif
109
110
111
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)