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