BOSS
7.1.1
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.2 2015/04/07 07:39:37 pingrg 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
16
#include "
EvtGenBase/EvtStreamAdapter.hh
"
17
#include <iterator>
18
using
std::input_iterator_tag;
19
20
template
<
class
Po
int
>
21
class
EvtStreamInputIterator
{
22
public
:
23
24
typedef
input_iterator_tag
iterator_category
;
25
typedef
Point
value_type
;
26
//typedef ptrdiff_t difference_type;
27
typedef
const
Point*
pointer
;
28
typedef
const
Point&
reference
;
29
30
EvtStreamInputIterator
()
31
:
_counter
(0)
32
{}
33
34
EvtStreamInputIterator
(
const
EvtStreamInputIterator
& other)
35
:
_counter
(other.
_counter
? other.
_counter
->clone() : 0),
36
_currentValue
(other.
_currentValue
)
37
{}
38
39
EvtStreamInputIterator
(
EvtStreamAdapter<Point>
& counter)
40
:
_counter
(counter.clone())
41
{
42
_currentValue
=
_counter
->currentValue();
43
}
44
45
~EvtStreamInputIterator
()
46
{
47
if
(
_counter
)
delete
_counter
;
48
}
49
50
reference
operator*
()
const
51
{
52
return
_currentValue
;
53
}
54
55
EvtStreamInputIterator
&
operator++
()
56
{
57
_read
();
58
return
*
this
;
59
}
60
61
EvtStreamInputIterator
operator++
(
int
)
62
{
63
EvtStreamInputIterator
tmp = *
this
;
64
_read
();
65
return
tmp;
66
}
67
68
bool
operator==
(
const
EvtStreamInputIterator
& other)
const
69
{
70
// Equality is only defined for two past the end iterators
71
return
(
pastEnd
() && other.pastEnd());
72
}
73
74
protected
:
75
76
EvtStreamAdapter<Point>
*
_counter
;
77
value_type
_currentValue
;
78
79
bool
pastEnd
()
const
80
{
81
bool
ret =
true
;
82
if
(
_counter
) ret =
_counter
->pastEnd();
83
return
ret;
84
}
85
86
// Advances the iterator
87
88
void
_read
() {
89
90
_counter
->advance();
91
_currentValue
=
_counter
->currentValue();
92
}
93
};
94
95
96
// For adaptable generators these shorthand functions can be used
97
// to construct iterators.
98
99
template
<
class
Generator>
100
EvtStreamInputIterator<typename Generator::result_type>
iter
(Generator gen,
int
N = 0)
101
{
102
typedef
typename
Generator::result_type Point;
103
EvtGenStreamAdapter<Point,Generator>
counter(gen,N);
104
return
EvtStreamInputIterator<Point>
(counter);
105
}
106
107
108
#endif
109
110
111
EvtStreamAdapter.hh
iter
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
Definition
EvtStreamInputIterator.hh:100
EvtGenStreamAdapter
Definition
EvtStreamAdapter.hh:35
EvtStreamAdapter
Definition
EvtStreamAdapter.hh:18
EvtStreamInputIterator
Definition
EvtStreamInputIterator.hh:21
EvtStreamInputIterator::operator*
reference operator*() const
Definition
EvtStreamInputIterator.hh:50
EvtStreamInputIterator::operator++
EvtStreamInputIterator operator++(int)
Definition
EvtStreamInputIterator.hh:61
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(const EvtStreamInputIterator &other)
Definition
EvtStreamInputIterator.hh:34
EvtStreamInputIterator::pointer
const Point * pointer
Definition
EvtStreamInputIterator.hh:27
EvtStreamInputIterator::operator==
bool operator==(const EvtStreamInputIterator &other) const
Definition
EvtStreamInputIterator.hh:68
EvtStreamInputIterator::_currentValue
value_type _currentValue
Definition
EvtStreamInputIterator.hh:77
EvtStreamInputIterator::iterator_category
input_iterator_tag iterator_category
Definition
EvtStreamInputIterator.hh:24
EvtStreamInputIterator::_counter
EvtStreamAdapter< Point > * _counter
Definition
EvtStreamInputIterator.hh:76
EvtStreamInputIterator::_read
void _read()
Definition
EvtStreamInputIterator.hh:88
EvtStreamInputIterator::pastEnd
bool pastEnd() const
Definition
EvtStreamInputIterator.hh:79
EvtStreamInputIterator::value_type
Point value_type
Definition
EvtStreamInputIterator.hh:25
EvtStreamInputIterator::reference
const Point & reference
Definition
EvtStreamInputIterator.hh:28
EvtStreamInputIterator::operator++
EvtStreamInputIterator & operator++()
Definition
EvtStreamInputIterator.hh:55
EvtStreamInputIterator::~EvtStreamInputIterator
~EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:45
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:30
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)
Definition
EvtStreamInputIterator.hh:39
7.1.1
Generator
BesEvtGen
BesEvtGen-00-04-28
src
EvtGen
EvtGenBase
EvtStreamInputIterator.hh
Generated by
1.12.0