libcryfs/implementations/onblocks/datatreestore/DataTreeStore.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

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"
2015-06-26 15:59:18 +02:00
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using boost::optional;
using boost::none;
2015-01-23 04:39:36 +01:00
using blobstore::onblocks::datanodestore::DataNodeStore;
using blobstore::onblocks::datanodestore::DataNode;
namespace blobstore {
namespace onblocks {
namespace datatreestore {
2015-06-26 15:59:18 +02:00
DataTreeStore::DataTreeStore(unique_ref<DataNodeStore> nodeStore)
2015-01-23 04:39:36 +01:00
: _nodeStore(std::move(nodeStore)) {
}
DataTreeStore::~DataTreeStore() {
}
2015-06-26 15:59:18 +02:00
optional<unique_ref<DataTree>> DataTreeStore::load(const blockstore::Key &key) {
auto node = _nodeStore->load(key);
2015-06-26 15:59:18 +02:00
if (node == none) {
return none;
}
2015-06-26 15:59:18 +02:00
return make_unique_ref<DataTree>(_nodeStore.get(), std::move(*node));
2015-01-23 04:39:36 +01:00
}
2015-06-26 15:59:18 +02:00
unique_ref<DataTree> DataTreeStore::createNewTree() {
auto newleaf = _nodeStore->createNewLeafNode();
return make_unique_ref<DataTree>(_nodeStore.get(), std::move(newleaf));
2015-01-23 04:39:36 +01:00
}
2015-06-26 15:59:18 +02:00
void DataTreeStore::remove(unique_ref<DataTree> tree) {
auto root = tree->releaseRootNode();
cpputils::destruct(std::move(tree)); // Destruct tree
_nodeStore->removeSubtree(std::move(root));
}
2015-01-23 04:39:36 +01:00
}
}
}