#include "OnDiskBlock.h" #include "OnDiskBlockStore.h" using std::unique_ptr; using std::make_unique; using std::string; using cpputils::Data; using cpputils::unique_ref; using boost::optional; using boost::none; namespace bf = boost::filesystem; namespace blockstore { namespace ondisk { OnDiskBlockStore::OnDiskBlockStore(const boost::filesystem::path &rootdir) : _rootdir(rootdir) {} optional> OnDiskBlockStore::tryCreate(const Key &key, Data data) { //TODO Easier implementation? This is only so complicated because of the cast OnDiskBlock -> Block auto result = std::move(OnDiskBlock::CreateOnDisk(_rootdir, key, std::move(data))); if (result == boost::none) { return boost::none; } return unique_ref(std::move(*result)); } optional> OnDiskBlockStore::load(const Key &key) { return optional>(OnDiskBlock::LoadFromDisk(_rootdir, key)); } void OnDiskBlockStore::remove(unique_ref block) { Key key = block->key(); //TODO Better way to destruct? cpputils::to_unique_ptr(std::move(block)); // Destruct OnDiskBlock::RemoveFromDisk(_rootdir, key); } uint64_t OnDiskBlockStore::numBlocks() const { return std::distance(bf::directory_iterator(_rootdir), bf::directory_iterator()); } } }