1
0
Fork 0

implementing code review: clearing out Store

This commit is contained in:
Kaveh Vahedipour 2016-04-05 18:15:17 +02:00
parent 54bf795bbc
commit bb6461f3d7
2 changed files with 18 additions and 22 deletions

View File

@ -164,17 +164,12 @@ NodeType Node::type() const {
return _children.size() ? NODE : LEAF; return _children.size() ? NODE : LEAF;
} }
// Get child by name // lh-value at path vector
Node& Node::operator [](std::string const& name) {
return *_children[name];
}
//
Node& Node::operator ()(std::vector<std::string> const& pv) { Node& Node::operator ()(std::vector<std::string> const& pv) {
if (pv.size()) { if (pv.size()) {
std::string const key = pv.at(0); std::string const key = pv.at(0);
if (_children.find(key) == _children.end()) { if (_children.find(key) == _children.end()) {
_children[key] = std::make_shared<Node>(pv[0], this); _children[key] = std::make_shared<Node>(key, this);
} }
auto pvc(pv); auto pvc(pv);
pvc.erase(pvc.begin()); pvc.erase(pvc.begin());
@ -184,12 +179,13 @@ Node& Node::operator ()(std::vector<std::string> const& pv) {
} }
} }
// rh-value at path vector
Node const& Node::operator ()(std::vector<std::string> const& pv) const { Node const& Node::operator ()(std::vector<std::string> const& pv) const {
if (pv.size()) { if (pv.size()) {
std::string const key = pv.at(0); std::string const key = pv.at(0);
if (_children.find(key) == _children.end()) { if (_children.find(key) == _children.end()) {
throw StoreException(std::string("Node ") + key + throw StoreException(
std::string(" not found")); std::string("Node ") + key + std::string(" not found"));
} }
const Node& child = *_children.at(key); const Node& child = *_children.at(key);
auto pvc(pv); auto pvc(pv);
@ -199,17 +195,20 @@ Node const& Node::operator ()(std::vector<std::string> const& pv) const {
return *this; return *this;
} }
} }
Node const& Node::operator ()(std::string const& path) const {
PathType pv = split(path,'/');
return this->operator()(pv);
}
// lh-value at path
Node& Node::operator ()(std::string const& path) { Node& Node::operator ()(std::string const& path) {
PathType pv = split(path,'/'); PathType pv = split(path,'/');
return this->operator()(pv); return this->operator()(pv);
} }
// rh-value at path
Node const& Node::operator ()(std::string const& path) const {
PathType pv = split(path,'/');
return this->operator()(pv);
}
// lh-store
Node const& Node::root() const { Node const& Node::root() const {
Node *par = _parent, *tmp = 0; Node *par = _parent, *tmp = 0;
while (par != 0) { while (par != 0) {
@ -219,6 +218,7 @@ Node const& Node::root() const {
return *tmp; return *tmp;
} }
// rh-store
Node& Node::root() { Node& Node::root() {
Node *par = _parent, *tmp = 0; Node *par = _parent, *tmp = 0;
while (par != 0) { while (par != 0) {
@ -228,10 +228,12 @@ Node& Node::root() {
return *tmp; return *tmp;
} }
// velocypack value type of this node
ValueType Node::valueType() const { ValueType Node::valueType() const {
return slice().type(); return slice().type();
} }
// file time to live entry for this node to now + millis
bool Node::addTimeToLive (long millis) { bool Node::addTimeToLive (long millis) {
auto tkey = std::chrono::system_clock::now() + auto tkey = std::chrono::system_clock::now() +
std::chrono::milliseconds(millis); std::chrono::milliseconds(millis);
@ -242,6 +244,7 @@ bool Node::addTimeToLive (long millis) {
return true; return true;
} }
// remove time to live entry for this node
bool Node::removeTimeToLive () { bool Node::removeTimeToLive () {
if (_ttl != std::chrono::system_clock::time_point()) { if (_ttl != std::chrono::system_clock::time_point()) {
auto ret = root()._time_table.equal_range(_ttl); auto ret = root()._time_table.equal_range(_ttl);
@ -254,6 +257,7 @@ bool Node::removeTimeToLive () {
return true; return true;
} }
// Add observing url for this node
bool Node::addObserver (std::string const& uri) { bool Node::addObserver (std::string const& uri) {
auto it = std::find(_observers.begin(), _observers.end(), uri); auto it = std::find(_observers.begin(), _observers.end(), uri);
if (it==_observers.end()) { if (it==_observers.end()) {

View File

@ -103,11 +103,6 @@ public:
/// @brief Type of this node (LEAF / NODE) /// @brief Type of this node (LEAF / NODE)
NodeType type() const; NodeType type() const;
/// @brief Get child specified by name
Node& operator [](std::string const& name);
/// @brief Get child specified by name
Node const& operator [](std::string const& name) const;
/// @brief Get node specified by path vector /// @brief Get node specified by path vector
Node& operator ()(std::vector<std::string> const& pv); Node& operator ()(std::vector<std::string> const& pv);
/// @brief Get node specified by path vector /// @brief Get node specified by path vector
@ -118,9 +113,6 @@ public:
/// @brief Get node specified by path string /// @brief Get node specified by path string
Node const& operator ()(std::string const& path) const; Node const& operator ()(std::string const& path) const;
/// @brief Remove node at absolut path
//bool remove (std::string const& path);
/// @brief Remove child by name /// @brief Remove child by name
bool removeChild (std::string const& key); bool removeChild (std::string const& key);