evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtStreamInputIterator.hh
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #ifndef EVT_STREAM_INPUT_ITERATOR_HH
22 #define EVT_STREAM_INPUT_ITERATOR_HH
23 
25 
26 #include <cstddef>
27 #include <iterator>
28 
29 using std::input_iterator_tag;
30 
31 // Adapters are used to convert various types of input streams
32 // into an iteratable interface.
33 
34 template <class Point>
36  public:
37  typedef input_iterator_tag iterator_category;
38  typedef Point value_type;
39  typedef ptrdiff_t difference_type;
40  typedef const Point* pointer;
41  typedef const Point& reference;
42 
44 
46  _counter( other._counter ? other._counter->clone() : 0 ),
48  {
49  }
50 
52  _counter( counter.clone() )
53  {
54  _currentValue = _counter->currentValue();
55  }
56 
58  {
59  if ( _counter )
60  delete _counter;
61  }
62 
63  reference operator*() const { return _currentValue; }
64 
66  {
67  _read();
68  return *this;
69  }
70 
72  {
73  EvtStreamInputIterator tmp = *this;
74  _read();
75  return tmp;
76  }
77 
79  {
80  // Equality is only defined for two past the end iterators
81  return ( pastEnd() && other.pastEnd() );
82  }
83 
84  protected:
87 
88  bool pastEnd() const
89  {
90  bool ret = true;
91  if ( _counter )
92  ret = _counter->pastEnd();
93  return ret;
94  }
95 
96  // Advances the iterator
97 
98  void _read()
99  {
100  _counter->advance();
101  _currentValue = _counter->currentValue();
102  }
103 };
104 
105 // For adaptable generators these shorthand functions can be used
106 // to construct iterators.
107 
108 template <class Generator>
110  int N = 0 )
111 {
112  typedef typename Generator::result_type Point;
113  EvtGenStreamAdapter<Point, Generator> counter( gen, N );
114  return EvtStreamInputIterator<Point>( counter );
115 }
116 
117 #endif
EvtStreamAdapter< Point > * _counter
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
bool operator==(const EvtStreamInputIterator &other) const
EvtStreamInputIterator(const EvtStreamInputIterator &other)
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)
input_iterator_tag iterator_category
EvtStreamInputIterator operator++(int)
EvtStreamInputIterator & operator++()
Index other(Index i, Index j)
Definition: EvtCyclic3.cpp:156