-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathEventRange.h
More file actions
96 lines (70 loc) · 2.34 KB
/
Copy pathEventRange.h
File metadata and controls
96 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef EventRange_h
#define EventRange_h
#include <cassert>
#include <sstream>
#include <stdexcept>
#include "Framework/Event.h"
namespace edm {
class EventRange {
public:
EventRange(Event* begin, Event* end) : begin_(begin), end_(end) {
assert(begin_);
assert(end_);
assert(end_ >= begin_);
}
Event* begin() { return begin_; }
Event const* begin() const { return begin_; }
Event* end() { return end_; }
Event const* end() const { return end_; }
size_t size() const { return end_ - begin_; }
bool empty() const { return end_ == begin_; }
Event& at(size_t index) {
if (index >= size()) {
std::stringstream msg;
msg << "EventRange::at() range check failed: index " << index << " is outside the range [0.." << size() << ")";
throw std::out_of_range(msg.str());
}
return begin_[index];
}
Event const& at(size_t index) const {
if (index >= size()) {
std::stringstream msg;
msg << "EventRange::at() range check failed: index " << index << " is outside the range [0.." << size() << ")";
throw std::out_of_range(msg.str());
}
return begin_[index];
}
Event& operator[](size_t index) { return begin_[index]; }
Event const& operator[](size_t index) const { return begin_[index]; }
private:
Event* begin_;
Event* end_;
};
class ConstEventRange {
public:
ConstEventRange(Event const* begin, Event const* end) : begin_(begin), end_(end) {
assert(begin_);
assert(end_);
assert(end_ >= begin_);
}
ConstEventRange(EventRange range) : begin_(range.begin()), end_(range.end()) {}
Event const* begin() const { return begin_; }
Event const* end() const { return end_; }
size_t size() const { return end_ - begin_; }
bool empty() const { return end_ == begin_; }
Event const& at(size_t index) {
if (index >= size()) {
std::stringstream msg;
msg << "ConstEventRange::at() range check failed: index " << index << " is outside the range [0.." << size()
<< ")";
throw std::out_of_range(msg.str());
}
return begin_[index];
}
Event const& operator[](size_t index) const { return begin_[index]; }
private:
Event const* begin_;
Event const* end_;
};
} // namespace edm
#endif // EventRange_h