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
16
#include "
EvtGenBase/EvtStreamAdapter.hh
"
17
#include <iterator>
18
#include <cstddef>
19
using
std::input_iterator_tag;
20
21
template
<
class
Po
int
>
22
class
EvtStreamInputIterator
{
23
public
:
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
31
EvtStreamInputIterator
()
32
:
_counter
(0)
33
{}
34
35
EvtStreamInputIterator
(
const
EvtStreamInputIterator
& other)
36
:
_counter
(other.
_counter
? other.
_counter
->clone() : 0),
37
_currentValue
(other.
_currentValue
)
38
{}
39
40
EvtStreamInputIterator
(
EvtStreamAdapter<Point>
& counter)
41
:
_counter
(counter.clone())
42
{
43
_currentValue
=
_counter
->currentValue();
44
}
45
46
~EvtStreamInputIterator
()
47
{
48
if
(
_counter
)
delete
_counter
;
49
}
50
51
reference
operator*
()
const
52
{
53
return
_currentValue
;
54
}
55
56
EvtStreamInputIterator
&
operator++
()
57
{
58
_read
();
59
return
*
this
;
60
}
61
62
EvtStreamInputIterator
operator++
(
int
)
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
75
protected
:
76
77
EvtStreamAdapter<Point>
*
_counter
;
78
value_type
_currentValue
;
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
100
template
<
class
Generator>
101
EvtStreamInputIterator<typename Generator::result_type>
iter
(Generator gen,
int
N = 0)
102
{
103
typedef
typename
Generator::result_type Point;
104
EvtGenStreamAdapter<Point,Generator>
counter(gen,N);
105
return
EvtStreamInputIterator<Point>
(counter);
106
}
107
108
109
#endif
110
111
112
EvtStreamAdapter.hh
iter
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
Definition
EvtStreamInputIterator.hh:101
EvtGenStreamAdapter
Definition
EvtStreamAdapter.hh:35
EvtStreamAdapter
Definition
EvtStreamAdapter.hh:18
EvtStreamInputIterator
Definition
EvtStreamInputIterator.hh:22
EvtStreamInputIterator::operator*
reference operator*() const
Definition
EvtStreamInputIterator.hh:51
EvtStreamInputIterator::operator++
EvtStreamInputIterator operator++(int)
Definition
EvtStreamInputIterator.hh:62
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(const EvtStreamInputIterator &other)
Definition
EvtStreamInputIterator.hh:35
EvtStreamInputIterator::pointer
const Point * pointer
Definition
EvtStreamInputIterator.hh:28
EvtStreamInputIterator::operator==
bool operator==(const EvtStreamInputIterator &other) const
Definition
EvtStreamInputIterator.hh:69
EvtStreamInputIterator::_currentValue
value_type _currentValue
Definition
EvtStreamInputIterator.hh:78
EvtStreamInputIterator::iterator_category
input_iterator_tag iterator_category
Definition
EvtStreamInputIterator.hh:25
EvtStreamInputIterator::_counter
EvtStreamAdapter< Point > * _counter
Definition
EvtStreamInputIterator.hh:77
EvtStreamInputIterator::_read
void _read()
Definition
EvtStreamInputIterator.hh:89
EvtStreamInputIterator::pastEnd
bool pastEnd() const
Definition
EvtStreamInputIterator.hh:80
EvtStreamInputIterator::difference_type
ptrdiff_t difference_type
Definition
EvtStreamInputIterator.hh:27
EvtStreamInputIterator::value_type
Point value_type
Definition
EvtStreamInputIterator.hh:26
EvtStreamInputIterator::reference
const Point & reference
Definition
EvtStreamInputIterator.hh:29
EvtStreamInputIterator::operator++
EvtStreamInputIterator & operator++()
Definition
EvtStreamInputIterator.hh:56
EvtStreamInputIterator::~EvtStreamInputIterator
~EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:46
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator()
Definition
EvtStreamInputIterator.hh:31
EvtStreamInputIterator::EvtStreamInputIterator
EvtStreamInputIterator(EvtStreamAdapter< Point > &counter)
Definition
EvtStreamInputIterator.hh:40
6.6.5.h
Generator
BesEvtGen
BesEvtGen-00-01-96-slc6tag
src
EvtGen
EvtGenBase
EvtStreamInputIterator.hh
Generated by
1.12.0