EvtGen 2.2.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
Loading...
Searching...
No Matches
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
29using std::input_iterator_tag;
30
31// Adapters are used to convert various types of input streams
32// into an iteratable interface.
33
34template <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 m_counter( other.m_counter ? other.m_counter->clone() : nullptr ),
48 {
49 }
50
52 m_counter( counter.clone() )
53 {
54 m_currentValue = m_counter->currentValue();
55 }
56
58 {
59 if ( m_counter )
60 delete m_counter;
61 }
62
64
66 {
67 m_read();
68 return *this;
69 }
70
72 {
73 EvtStreamInputIterator tmp = *this;
74 m_read();
75 return tmp;
76 }
77
78 bool operator==( const EvtStreamInputIterator& other ) const
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 ( m_counter )
92 ret = m_counter->pastEnd();
93 return ret;
94 }
95
96 // Advances the iterator
97
98 void m_read()
99 {
100 m_counter->advance();
101 m_currentValue = m_counter->currentValue();
102 }
103};
104
105// For adaptable generators these shorthand functions can be used
106// to construct iterators.
107
108template <class Generator>
110 int N = 0 )
111{
112 typedef typename Generator::result_type Point;
114 return EvtStreamInputIterator<Point>( counter );
115}
116
117#endif
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
EvtStreamAdapter< Point > * m_counter
EvtStreamInputIterator operator++(int)
EvtStreamInputIterator(const EvtStreamInputIterator &other)
bool operator==(const EvtStreamInputIterator &other) const
input_iterator_tag iterator_category
EvtStreamInputIterator & operator++()
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)