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 const Point* pointer;
27 typedef const Point& reference;
29 EvtStreamInputIterator()
33 EvtStreamInputIterator(const EvtStreamInputIterator& other)
34 : _counter(other._counter ? other._counter->clone() : 0),
35 _currentValue(other._currentValue)
38 EvtStreamInputIterator(EvtStreamAdapter<Point>& counter)
39 : _counter(counter.clone())
41 _currentValue = _counter->currentValue();
44 ~EvtStreamInputIterator()
46 if(_counter) delete _counter;
49 reference operator*() const
54 EvtStreamInputIterator& operator++()
60 EvtStreamInputIterator operator++(int)
62 EvtStreamInputIterator tmp = *this;
67 bool operator==(const EvtStreamInputIterator& other) const
69 // Equality is only defined for two past the end iterators
70 return (pastEnd() && other.pastEnd());
75 EvtStreamAdapter<Point>* _counter;
76 value_type _currentValue;
81 if(_counter) ret = _counter->pastEnd();
85 // Advances the iterator
90 _currentValue = _counter->currentValue();
95 // For adaptable generators these shorthand functions can be used
96 // to construct iterators.
98 template <class Generator>
99 EvtStreamInputIterator<typename Generator::result_type> iter(Generator gen, int N = 0)
101 typedef typename Generator::result_type Point;
102 EvtGenStreamAdapter<Point,Generator> counter(gen,N);
103 return EvtStreamInputIterator<Point>(counter);