blob: 390f942a4329c5f1172ca748e9ac0d9bf6bc36f9 (
plain) (
blame)
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
|
#include <qpdf/SparseOHArray.hh>
#include <stdexcept>
static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull();
QPDFObjectHandle
SparseOHArray::at(int idx) const
{
auto const& iter = elements.find(idx);
return iter == elements.end() ? null_oh : (*iter).second;
}
void
SparseOHArray::remove_last()
{
if (this->n_elements == 0) {
throw std::logic_error("INTERNAL ERROR: attempt to remove"
" last item from empty SparseOHArray");
}
--this->n_elements;
this->elements.erase(this->n_elements);
}
void
SparseOHArray::disconnect()
{
for (auto& iter: this->elements) {
QPDFObjectHandle::DisconnectAccess::disconnect(iter.second);
}
}
void
SparseOHArray::erase(int at)
{
auto end = elements.end();
if (auto iter = elements.lower_bound(at); iter != end) {
if (iter->first == at) {
iter++;
elements.erase(at);
}
while (iter != end) {
auto nh = elements.extract(iter++);
--nh.key();
elements.insert(std::move(nh));
}
}
--n_elements;
}
SparseOHArray
SparseOHArray::copy()
{
SparseOHArray result;
result.n_elements = this->n_elements;
for (auto const& element: this->elements) {
auto value = element.second;
result.elements[element.first] =
value->getObjGen().isIndirect() ? value : value->copy();
}
return result;
}
SparseOHArray::const_iterator
SparseOHArray::begin() const
{
return this->elements.begin();
}
SparseOHArray::const_iterator
SparseOHArray::end() const
{
return this->elements.end();
}
|