1 /*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
4 * File: $Id: EvtStreamInputIterator.hh,v 1.1 2003/03/03 05:38:22 dvoretsk Exp $
5 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
10 // Adapters are used to convert various types of input streams
11 // into an iteratable interface.
13 #ifndef EVT_STREAM_INPUT_ITERATOR_HH
14 #define EVT_STREAM_INPUT_ITERATOR_HH
16 #include "EvtGenBase/EvtStreamAdapter.hh"
18 using std::input_iterator_tag;
20 template <class Point>
21 class EvtStreamInputIterator {
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;
30 EvtStreamInputIterator()
34 EvtStreamInputIterator(const EvtStreamInputIterator& other)
35 : _counter(other._counter ? other._counter->clone() : 0),
36 _currentValue(other._currentValue)
39 EvtStreamInputIterator(EvtStreamAdapter<Point>& counter)
40 : _counter(counter.clone())
42 _currentValue = _counter->currentValue();
45 ~EvtStreamInputIterator()
47 if(_counter) delete _counter;
50 reference operator*() const
55 EvtStreamInputIterator& operator++()
61 EvtStreamInputIterator operator++(int)
63 EvtStreamInputIterator tmp = *this;
68 bool operator==(const EvtStreamInputIterator& other) const
70 // Equality is only defined for two past the end iterators
71 return (pastEnd() && other.pastEnd());
76 EvtStreamAdapter<Point>* _counter;
77 value_type _currentValue;
82 if(_counter) ret = _counter->pastEnd();
86 // Advances the iterator
91 _currentValue = _counter->currentValue();
96 // For adaptable generators these shorthand functions can be used
97 // to construct iterators.
99 template <class Generator>
100 EvtStreamInputIterator<typename Generator::result_type> iter(Generator gen, int N = 0)
102 typedef typename Generator::result_type Point;
103 EvtGenStreamAdapter<Point,Generator> counter(gen,N);
104 return EvtStreamInputIterator<Point>(counter);