libcryfs/interface/BlockStore.h

38 lines
956 B
C
Raw Normal View History

2014-12-09 17:19:59 +01:00
#pragma once
#ifndef FSPP_BLOCKSTORE_BLOCKSTORE_H_
#define FSPP_BLOCKSTORE_BLOCKSTORE_H_
#include "Block.h"
2014-12-09 17:19:59 +01:00
#include <string>
#include <memory>
#include <messmer/cpp-utils/data/Data.h>
2014-12-09 17:19:59 +01:00
namespace blockstore {
class BlockStore {
public:
virtual ~BlockStore() {}
virtual Key createKey() = 0;
//Returns nullptr if key already exists
virtual std::unique_ptr<Block> tryCreate(const Key &key, cpputils::Data data) = 0;
2014-12-09 17:19:59 +01:00
//TODO Use boost::optional (if key doesn't exist)
// Return nullptr if block with this key doesn't exists
virtual std::unique_ptr<Block> load(const Key &key) = 0;
virtual void remove(std::unique_ptr<Block> block) = 0;
2015-02-23 21:07:07 +01:00
virtual uint64_t numBlocks() const = 0;
std::unique_ptr<Block> create(const cpputils::Data &data) {
2015-04-24 13:42:37 +02:00
std::unique_ptr<Block> block(nullptr);
while(block.get() == nullptr) {
//TODO Copy necessary?
block = tryCreate(createKey(), data.copy());
}
return block;
}
2014-12-09 17:19:59 +01:00
};
}
#endif