From ac52b477085c4efa9df34d694e0ea1f564941619 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Fri, 11 Mar 2016 12:10:39 +0100 Subject: [PATCH] actually getting out what was put into kv-store --- arangod/Agency/Store.cpp | 53 ++++++++++++++++++++-------------------- arangod/Agency/Store.h | 4 ++- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/arangod/Agency/Store.cpp b/arangod/Agency/Store.cpp index b79a5b5e2f..81dfbe92da 100644 --- a/arangod/Agency/Store.cpp +++ b/arangod/Agency/Store.cpp @@ -67,11 +67,9 @@ Node& Node::operator= (Slice const& slice) { // Assign value (become leaf) } Node& Node::operator= (Node const& node) { // Assign node - - _value.reset(); - _value.append((char const*)node._value.data(),node._value.byteSize()); _name = node._name; _type = node._type; + _value = node._value; _children = node._children; return *this; } @@ -157,6 +155,23 @@ bool Node::apply (arangodb::velocypack::Slice const& slice) { return true; } +void Node::toBuilder (Builder& builder) const { + try { + if (type()==NODE) { + VPackObjectBuilder guard(&builder); + for (auto const& child : _children) { + std::cout << _name << " : " <toBuilder(builder); + } + } else { + builder.add(Slice(_value.data())); + } + } catch (std::exception const& e) { + LOG(FATAL) << e.what(); + } +} + Store::Store () : Node("root") {} Store::~Store () {} @@ -211,8 +226,9 @@ query_t Store::read (query_t const& queries) const { // list of list of paths return result; } -bool Store::read (arangodb::velocypack::Slice const& query, - Builder& ret) const { +bool Store::read (arangodb::velocypack::Slice const& query, Builder& ret) const { + + // Collect all paths std::list query_strs; if (query.type() == VPackValueType::Array) { for (auto const& sub_query : VPackArrayIterator(query)) @@ -224,7 +240,7 @@ bool Store::read (arangodb::velocypack::Slice const& query, } query_strs.sort(); // sort paths - // remove "double" entries + // Remove double ranges (inclusion / identity) for (auto i = query_strs.begin(), j = i; i != query_strs.end(); ++i) { if (i!=j && i->compare(0,j->size(),*j)==0) { *i=""; @@ -235,32 +251,17 @@ bool Store::read (arangodb::velocypack::Slice const& query, auto cut = std::remove_if(query_strs.begin(), query_strs.end(), Empty()); query_strs.erase (cut,query_strs.end()); + // Create response tree Node node("root"); for (auto i = query_strs.begin(); i != query_strs.end(); ++i) { node(*i) = (*this)(*i); } - - std::cout << node << std::endl; + + // Assemble builder from node + node.toBuilder(ret); + return true; } -/* -{ - Node* par = n._parent; - while (par != 0) { - par = par->_parent; - os << " "; - } - os << n._name << " : "; - if (n.type() == NODE) { - os << std::endl; - for (auto const& i : n._children) - os << *(i.second); - } else { - os << n._value.toString() << std::endl; - } - return os; -} -*/ diff --git a/arangod/Agency/Store.h b/arangod/Agency/Store.h index 044372a896..dc79996a3b 100644 --- a/arangod/Agency/Store.h +++ b/arangod/Agency/Store.h @@ -100,13 +100,15 @@ public: for (auto const& i : n._children) os << *(i.second); } else { - os << n._value.toString() << std::endl; + os << Slice(n._value.data()).toJson() << std::endl; } return os; } virtual bool apply (arangodb::velocypack::Slice const&); + void toBuilder (Builder&) const; + protected: Node const* _parent; Children _children;