2015-01-23 04:39:36 +01:00
|
|
|
#include "DataTreeStore.h"
|
2015-02-17 00:40:34 +01:00
|
|
|
#include "../datanodestore/DataNodeStore.h"
|
|
|
|
#include "../datanodestore/DataLeafNode.h"
|
2015-01-23 04:39:36 +01:00
|
|
|
#include "DataTree.h"
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
|
|
|
|
using blobstore::onblocks::datanodestore::DataNodeStore;
|
|
|
|
using blobstore::onblocks::datanodestore::DataNode;
|
|
|
|
|
|
|
|
namespace blobstore {
|
|
|
|
namespace onblocks {
|
|
|
|
namespace datatreestore {
|
|
|
|
|
|
|
|
DataTreeStore::DataTreeStore(unique_ptr<DataNodeStore> nodeStore)
|
|
|
|
: _nodeStore(std::move(nodeStore)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTreeStore::~DataTreeStore() {
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<DataTree> DataTreeStore::load(const blockstore::Key &key) {
|
2015-02-24 22:44:10 +01:00
|
|
|
auto node = _nodeStore->load(key);
|
|
|
|
if (node.get() == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
return make_unique<DataTree>(_nodeStore.get(), std::move(node));
|
|
|
|
}
|
2015-01-23 04:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<DataTree> DataTreeStore::createNewTree() {
|
|
|
|
unique_ptr<DataNode> newleaf = _nodeStore->createNewLeafNode();
|
|
|
|
return make_unique<DataTree>(_nodeStore.get(), std::move(newleaf));
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:44:10 +01:00
|
|
|
void DataTreeStore::remove(unique_ptr<DataTree> tree) {
|
|
|
|
auto root = tree->releaseRootNode();
|
|
|
|
tree.reset();
|
|
|
|
_nodeStore->removeSubtree(std::move(root));
|
|
|
|
}
|
|
|
|
|
2015-01-23 04:39:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|