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
EvtGenBase
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
24
#include "
EvtGenBase/EvtStreamAdapter.hh
"
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
Po
int
>
35
class
EvtStreamInputIterator
{
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
43
EvtStreamInputIterator
() :
m_counter
( 0 ) {}
44
45
EvtStreamInputIterator
(
const
EvtStreamInputIterator
& other ) :
46
m_counter
( other.
m_counter
? other.
m_counter
->clone() : nullptr ),
47
m_currentValue
( other.
m_currentValue
)
48
{
49
}
50
51
EvtStreamInputIterator
(
EvtStreamAdapter<Point>
& counter ) :
52
m_counter
( counter.clone() )
53
{
54
m_currentValue
=
m_counter
->currentValue();
55
}
56
57
~EvtStreamInputIterator
()
58
{
59
if
(
m_counter
)
60
delete
m_counter
;
61
}
62
63
reference
operator*
()
const
{
return
m_currentValue
; }
64
65
EvtStreamInputIterator
&
operator++
()
66
{
67
m_read
();
68
return
*
this
;
69
}
70
71
EvtStreamInputIterator
operator++
(
int
)
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
:
85
EvtStreamAdapter<Point>
*
m_counter
;
86
value_type
m_currentValue
;
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
108
template
<
class
Generator>
109
EvtStreamInputIterator<typename Generator::result_type>
iter
( Generator gen,
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.hh
iter
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
Definition
EvtStreamInputIterator.hh:109
EvtGenStreamAdapter
Definition
EvtStreamAdapter.hh:43
EvtStreamAdapter
Definition
EvtStreamAdapter.hh:30
EvtStreamInputIterator
Definition
EvtStreamInputIterator.hh:35
EvtStreamInputIterator::operator*
reference operator*() const
Definition
EvtStreamInputIterator.hh:63
EvtStreamInputIterator::m_counter
EvtStreamAdapter< Point > * m_counter
Definition
EvtStreamInputIterator.hh:85
EvtStreamInputIterator::reference
const Point & reference
Definition
EvtStreamInputIterator.hh:41
EvtStreamInputIterator::operator++
EvtStreamInputIterator operator++(int)
Definition
EvtStreamInputIterator.hh:71
EvtStreamInputIterator::m_currentValue
value_type m_currentValue
Definition
EvtStreamInputIterator.hh:86
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(const EvtStreamInputIterator &other)
Definition
EvtStreamInputIterator.hh:45
EvtStreamInputIterator::difference_type
ptrdiff_t difference_type
Definition
EvtStreamInputIterator.hh:39
EvtStreamInputIterator::pointer
const Point * pointer
Definition
EvtStreamInputIterator.hh:40
EvtStreamInputIterator::value_type
Point value_type
Definition
EvtStreamInputIterator.hh:38
EvtStreamInputIterator::operator==
bool operator==(const EvtStreamInputIterator &other) const
Definition
EvtStreamInputIterator.hh:78
EvtStreamInputIterator::iterator_category
input_iterator_tag iterator_category
Definition
EvtStreamInputIterator.hh:37
EvtStreamInputIterator::m_read
void m_read()
Definition
EvtStreamInputIterator.hh:98
EvtStreamInputIterator::pastEnd
bool pastEnd() const
Definition
EvtStreamInputIterator.hh:88
EvtStreamInputIterator::operator++
EvtStreamInputIterator & operator++()
Definition
EvtStreamInputIterator.hh:65
EvtStreamInputIterator::~EvtStreamInputIterator
~EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:57
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:43
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)
Definition
EvtStreamInputIterator.hh:51
Generated by
1.16.1