forked from scikit-hep/awkward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Iterator.cpp
62 lines (51 loc) · 1.42 KB
/
Iterator.cpp
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
// BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE
#include <sstream>
#include "awkward/Content.h"
#include "awkward/array/VirtualArray.h"
#include "awkward/Iterator.h"
namespace awkward {
const ContentPtr nonvirtual(const ContentPtr& content) {
if (VirtualArray* raw = dynamic_cast<VirtualArray*>(content.get())) {
return raw->array();
}
else {
return content;
}
}
Iterator::Iterator(const ContentPtr& content)
: content_(nonvirtual(content))
, at_(0) {
content.get()->check_for_iteration();
}
const ContentPtr
Iterator::content() const {
return content_;
}
const int64_t
Iterator::at() const {
return at_;
}
const bool
Iterator::isdone() const {
return at_ >= content_.get()->length();
}
const ContentPtr
Iterator::next() {
return content_.get()->getitem_at_nowrap(at_++);
}
const std::string
Iterator::tostring_part(const std::string& indent,
const std::string& pre,
const std::string& post) const {
std::stringstream out;
out << indent << pre << "<Iterator at=\"" << at_ << "\">\n";
out << content_.get()->tostring_part(
indent + std::string(" "), "", "\n");
out << indent << "</Iterator>" << post;
return out.str();
}
const std::string
Iterator::tostring() const {
return tostring_part("", "", "");
}
}