mirror of https://gitee.com/bigwinds/arangodb
Construct builder with prefilled buffer. Agency store increment, decrement, push pop
This commit is contained in:
parent
5acdc36d07
commit
af56c18345
|
@ -176,72 +176,68 @@ Node& Node::write (std::string const& path) {
|
||||||
|
|
||||||
bool Node::applies (arangodb::velocypack::Slice const& slice) {
|
bool Node::applies (arangodb::velocypack::Slice const& slice) {
|
||||||
if (slice.type() == ValueType::Object) {
|
if (slice.type() == ValueType::Object) {
|
||||||
VPackObjectIterator sit (slice);
|
for (auto const& i : VPackObjectIterator(slice)) {
|
||||||
|
std::string key = i.key.toString();
|
||||||
auto b = sit.begin();
|
key = key.substr(1,key.length()-2);
|
||||||
auto i = *b;
|
if (key == "op") {
|
||||||
std::string key = i.key.toString();
|
std::string oper = i.value.toString();
|
||||||
key = key.substr(1,key.length()-2);
|
oper = oper.substr(1,oper.length()-2);
|
||||||
if (key == "op") {
|
Slice const& self = this->slice();
|
||||||
std::string oper = i.value.toString();
|
if (oper == "delete") {
|
||||||
oper = oper.substr(1,oper.length()-2);
|
return _parent->removeChild(_name);
|
||||||
Slice const& self = this->slice();
|
} else if (oper == "increment") { // Increment
|
||||||
if (oper == "delete") {
|
if (self.isInt() || self.isUInt()) {
|
||||||
return _parent->removeChild(_name);
|
Builder tmp;
|
||||||
} else if (oper == "increment") { // Increment
|
tmp.add(Value(self.isInt() ? int64_t(self.getInt()+1) : uint64_t(self.getUInt()+1)));
|
||||||
if (self.isInt() || self.isUInt()) {
|
*this = tmp.slice();
|
||||||
Builder tmp;
|
return true;
|
||||||
tmp.add(Value(self.isInt() ? int64_t(self.getInt()+1) : uint64_t(self.getUInt()+1)));
|
} else {
|
||||||
*this = tmp.slice();
|
return false;
|
||||||
return true;
|
}
|
||||||
} else {
|
} else if (oper == "increment") { // Decrement
|
||||||
return false;
|
if (self.isInt() || self.isUInt()) {
|
||||||
}
|
Builder tmp;
|
||||||
} else if (oper == "increment") { // Decrement
|
tmp.add(Value(self.isInt() ? int64_t(self.getInt()-1) : uint64_t(self.getUInt()-1)));
|
||||||
if (self.isInt() || self.isUInt()) {
|
*this = tmp.slice();
|
||||||
Builder tmp;
|
return true;
|
||||||
tmp.add(Value(self.isInt() ? int64_t(self.getInt()-1) : uint64_t(self.getUInt()-1)));
|
} else {
|
||||||
*this = tmp.slice();
|
return false;
|
||||||
return true;
|
}
|
||||||
} else {
|
} else if (oper == "push") { // Push
|
||||||
return false;
|
if (self.isArray()) {
|
||||||
}
|
Builder tmp;
|
||||||
} else if (oper == "push") { // Push
|
tmp.openArray();
|
||||||
if (self.isArray()) {
|
for (auto const& old : VPackArrayIterator(self))
|
||||||
Builder tmp;
|
tmp.add(old);
|
||||||
tmp.openArray();
|
tmp.close();
|
||||||
for (auto const& old : VPackArrayIterator(self))
|
*this = tmp.slice();
|
||||||
tmp.add(old);
|
}
|
||||||
tmp.close();
|
} else if (oper == "pop") { // Pop
|
||||||
auto nval = *++b;
|
if (self.isArray()) {
|
||||||
std::cout << nval.value.toString() << std::endl;
|
Builder tmp;
|
||||||
*this = tmp.slice();
|
tmp.openArray();
|
||||||
}
|
VPackArrayIterator it(self);
|
||||||
} else if (oper == "pop") { // Pop
|
size_t j = it.size()-1;
|
||||||
if (self.isArray()) {
|
std::cout << j << std::endl;
|
||||||
Builder tmp;
|
for (auto old : it) {
|
||||||
tmp.openArray();
|
tmp.add(old);
|
||||||
VPackArrayIterator it(self);
|
if (--j==0)
|
||||||
size_t j = it.size()-1;
|
break;
|
||||||
for (auto old : it) {
|
}
|
||||||
tmp.add(old);
|
tmp.close();
|
||||||
if (--j==0)
|
*this = tmp.slice();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
tmp.close();
|
|
||||||
*this = tmp.slice();
|
|
||||||
}
|
}
|
||||||
}
|
} else if (key.find('/')!=std::string::npos) {
|
||||||
} else if (key.find('/')!=std::string::npos) {
|
(*this)(key).applies(i.value);
|
||||||
(*this)(key).applies(i.value);
|
} else {
|
||||||
} else {
|
auto found = _children.find(key);
|
||||||
auto found = _children.find(key);
|
if (found == _children.end()) {
|
||||||
if (found == _children.end()) {
|
_children[key] = std::make_shared<Node>(key, this);
|
||||||
_children[key] = std::make_shared<Node>(key, this);
|
}
|
||||||
}
|
|
||||||
_children[key]->applies(i.value);
|
_children[key]->applies(i.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
*this = slice;
|
*this = slice;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue