-
-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathDumbHostObject.cpp
More file actions
72 lines (58 loc) · 1.9 KB
/
Copy pathDumbHostObject.cpp
File metadata and controls
72 lines (58 loc) · 1.9 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
#include "DumbHostObject.hpp"
#include "SmartHostObject.hpp"
#include "utils.hpp"
#include <iostream>
namespace opsqlite {
namespace jsi = facebook::jsi;
DumbHostObject::DumbHostObject(
std::shared_ptr<std::vector<SmartHostObject>> metadata) {
this->metadata = metadata;
};
std::vector<jsi::PropNameID>
DumbHostObject::getPropertyNames(jsi::Runtime &rt) {
std::vector<jsi::PropNameID> keys;
for (auto field : *metadata) {
// TODO improve this by generating the propName once on metadata
// creation
keys.push_back(jsi::PropNameID::forAscii(
rt, std::get<std::string>(field.fields[0].second)));
}
return keys;
}
jsi::Value DumbHostObject::get(jsi::Runtime &rt,
const jsi::PropNameID &propNameID) {
auto name = propNameID.utf8(rt);
auto fields = metadata.get();
for (int i = 0; i < fields->size(); i++) {
auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
if (fieldName == name) {
return to_jsi(rt, values.at(i));
}
}
for (auto pairField : ownValues) {
if (name == pairField.first) {
return to_jsi(rt, pairField.second);
}
}
return {};
}
void DumbHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
const jsi::Value &value) {
auto key = name.utf8(rt);
auto fields = metadata.get();
for (int i = 0; i < fields->size(); i++) {
auto fieldName = std::get<std::string>(fields->at(i).fields[0].second);
if (fieldName == key) {
values[i] = to_variant(rt, value);
return;
}
}
for (auto pairField : ownValues) {
if (key == pairField.first) {
pairField.second = to_variant(rt, value);
return;
}
}
ownValues.push_back(std::make_pair(key, to_variant(rt, value)));
}
} // namespace opsqlite