blob: e2743449eb3530f751ee7260204140f7041d8212 (
plain)
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
|
#include "List.hpp"
#include <utility>
BaseValue* ListValue::Iterator::operator*() const {
return mIter->get();
}
BaseValue* ListValue::Iterator::operator->() const {
return mIter->get();
}
ListValue::Iterator& ListValue::Iterator::operator++() {
++mIter;
return *this;
}
ListValue::Iterator ListValue::Iterator::operator++(int) const {
return Iterator(mIter + 1);
}
ListValue::Iterator& ListValue::Iterator::operator--() {
--mIter;
return *this;
}
ListValue::Iterator ListValue::Iterator::operator--(int) const {
return Iterator(mIter - 1);
}
bool operator==(const ListValue::Iterator& a, const ListValue::Iterator& b) {
return a.mIter == b.mIter;
}
ListValue::Iterator::Iterator(decltype(mIter) iter)
: mIter{ iter } {
}
bool ListValue::IsInstance(const BaseValue* value) {
return value->GetKind() == KD_List;
}
ListValue::ListValue()
: BaseValue(KD_List) {
}
int ListValue::GetCount() const {
return mElements.size();
}
BaseValue* ListValue::GetElement(int i) const {
return mElements[i].get();
}
void ListValue::Append(std::unique_ptr<BaseValue> element) {
mElements.push_back(std::move(element));
}
void ListValue::Insert(int i, std::unique_ptr<BaseValue> element) {
mElements.insert(mElements.begin() + i, std::move(element));
}
void ListValue::Insert(Iterator iter, std::unique_ptr<BaseValue> element) {
mElements.insert(iter.mIter, std::move(element));
}
void ListValue::Remove(int i) {
mElements.erase(mElements.begin() + i);
}
void ListValue::Remove(Iterator iter) {
mElements.erase(iter.mIter);
}
ListValue::Iterator ListValue::begin() {
return Iterator(mElements.begin());
}
ListValue::Iterator ListValue::end() {
return Iterator(mElements.end());
}
|