CGEM BOSS 6.6.5.h
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.1.1.2.2.1 2014/04/18 00:35:09 maqm 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>
18#include <cstddef>
19using std::input_iterator_tag;
20
21template <class Point>
23public:
24
25 typedef input_iterator_tag iterator_category;
26 typedef Point value_type;
27 typedef ptrdiff_t difference_type;
28 typedef const Point* pointer;
29 typedef const Point& reference;
30
34
36 : _counter(other._counter ? other._counter->clone() : 0),
38 {}
39
41 : _counter(counter.clone())
42 {
43 _currentValue = _counter->currentValue();
44 }
45
47 {
48 if(_counter) delete _counter;
49 }
50
52 {
53 return _currentValue;
54 }
55
57 {
58 _read();
59 return *this;
60 }
61
63 {
64 EvtStreamInputIterator tmp = *this;
65 _read();
66 return tmp;
67 }
68
69 bool operator==(const EvtStreamInputIterator& other) const
70 {
71 // Equality is only defined for two past the end iterators
72 return (pastEnd() && other.pastEnd());
73 }
74
75protected:
76
79
80 bool pastEnd() const
81 {
82 bool ret = true;
83 if(_counter) ret = _counter->pastEnd();
84 return ret;
85 }
86
87 // Advances the iterator
88
89 void _read() {
90
91 _counter->advance();
92 _currentValue = _counter->currentValue();
93 }
94};
95
96
97// For adaptable generators these shorthand functions can be used
98// to construct iterators.
99
100template <class Generator>
102{
103 typedef typename Generator::result_type Point;
105 return EvtStreamInputIterator<Point>(counter);
106}
107
108
109#endif
110
111
112
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)