1 /*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
4 * File: $Id: EvtStreamInputIterator.hh,v 1.2 2009-03-16 16:41:09 robbep 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"
21 using std::input_iterator_tag;
23 template <class Point>
24 class EvtStreamInputIterator {
27 typedef input_iterator_tag iterator_category;
28 typedef Point value_type;
29 typedef ptrdiff_t difference_type;
30 typedef const Point* pointer;
31 typedef const Point& reference;
33 EvtStreamInputIterator()
37 EvtStreamInputIterator(const EvtStreamInputIterator& other)
38 : _counter(other._counter ? other._counter->clone() : 0),
39 _currentValue(other._currentValue)
42 EvtStreamInputIterator(EvtStreamAdapter<Point>& counter)
43 : _counter(counter.clone())
45 _currentValue = _counter->currentValue();
48 ~EvtStreamInputIterator()
50 if(_counter) delete _counter;
53 reference operator*() const
58 EvtStreamInputIterator& operator++()
64 EvtStreamInputIterator operator++(int)
66 EvtStreamInputIterator tmp = *this;
71 bool operator==(const EvtStreamInputIterator& other) const
73 // Equality is only defined for two past the end iterators
74 return (pastEnd() && other.pastEnd());
79 EvtStreamAdapter<Point>* _counter;
80 value_type _currentValue;
85 if(_counter) ret = _counter->pastEnd();
89 // Advances the iterator
94 _currentValue = _counter->currentValue();
99 // For adaptable generators these shorthand functions can be used
100 // to construct iterators.
102 template <class Generator>
103 EvtStreamInputIterator<typename Generator::result_type> iter(Generator gen, int N = 0)
105 typedef typename Generator::result_type Point;
106 EvtGenStreamAdapter<Point,Generator> counter(gen,N);
107 return EvtStreamInputIterator<Point>(counter);