-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdynamic-list-reader.cpp
More file actions
93 lines (72 loc) · 2.41 KB
/
dynamic-list-reader.cpp
File metadata and controls
93 lines (72 loc) · 2.41 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
#include <iostream>
#include "dynamic-list-reader.h"
#include "dynamic-value-converter.h"
namespace capnp_php {
DynamicListReader::DynamicListReader(capnp::DynamicList::Reader reader,
Php::Object messageReader)
: Php::Base(),
Php::Countable(),
messageReader(messageReader),
reader(reader)
{
//Php::out << "DynamicListReader::DynamicListReader ctor " << (void*)this << std::endl;
}
DynamicListReader::~DynamicListReader() {
//Php::out << "DynamicListReader::~DynamicListReader dtor " << (void*)this << std::endl;
}
Php::Value DynamicListReader::getByIndex(int64_t index) {
return DynamicValueConverter::convertFromCapnp(reader[index], this);
}
long DynamicListReader::count() {
return static_cast<long>(reader.size());
}
bool DynamicListReader::offsetExists(const Php::Value &key) {
int64_t index = key;
return index < static_cast<int64_t>(reader.size());
}
Php::Value DynamicListReader::offsetGet(const Php::Value &key) {
return getByIndex(key);
}
void DynamicListReader::offsetSet(const Php::Value &key, const Php::Value &value) {
//throw Php::NotImplemented();
}
void DynamicListReader::offsetUnset(const Php::Value &key) {
//throw Php::NotImplemented();
}
class DynamicListReaderIterator : public Php::Iterator {
private:
long index;
DynamicListReader * reader;
public:
DynamicListReaderIterator(DynamicListReader * reader)
: Php::Iterator(reader),
index(0),
reader(reader)
{
}
virtual ~DynamicListReaderIterator() { }
virtual bool valid() override
{
return index < reader->count();
}
virtual Php::Value current() override
{
return reader->getByIndex(index);
}
virtual Php::Value key() override
{
return static_cast<int64_t>(index);
}
virtual void next() override
{
++index;
}
virtual void rewind() override
{
index = 0;
}
};
Php::Iterator * DynamicListReader::getIterator() {
return new DynamicListReaderIterator(this);
}
}