2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef FSPP_BLOCKSTORE_BLOCKSTORE_H_
|
|
|
|
#define FSPP_BLOCKSTORE_BLOCKSTORE_H_
|
|
|
|
|
2015-03-12 14:27:51 +01:00
|
|
|
#include "Block.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2015-04-18 14:47:12 +02:00
|
|
|
#include "../utils/Data.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
|
|
|
|
class BlockStore {
|
|
|
|
public:
|
|
|
|
virtual ~BlockStore() {}
|
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
virtual Key createKey() = 0;
|
|
|
|
//Returns nullptr if key already exists
|
|
|
|
virtual std::unique_ptr<Block> tryCreate(const Key &key, 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
|
2014-12-09 20:36:32 +01:00
|
|
|
virtual std::unique_ptr<Block> load(const Key &key) = 0;
|
2015-02-22 16:53:49 +01:00
|
|
|
virtual void remove(std::unique_ptr<Block> block) = 0;
|
2015-02-23 21:07:07 +01:00
|
|
|
virtual uint64_t numBlocks() const = 0;
|
2015-04-18 14:47:12 +02:00
|
|
|
|
|
|
|
std::unique_ptr<Block> create(const Data &data) {
|
|
|
|
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
|