2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_INTERFACE_BLOCKSTORE_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_INTERFACE_BLOCKSTORE_H_
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2015-03-12 14:27:51 +01:00
|
|
|
#include "Block.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <string>
|
2015-07-20 18:57:48 +02:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-04-25 02:48:41 +02:00
|
|
|
#include <messmer/cpp-utils/data/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;
|
2015-07-20 18:57:48 +02:00
|
|
|
//Returns boost::none if key already exists
|
|
|
|
virtual boost::optional<cpputils::unique_ref<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
|
2015-07-21 14:50:52 +02:00
|
|
|
virtual boost::optional<cpputils::unique_ref<Block>> load(const Key &key) = 0;
|
|
|
|
virtual void remove(cpputils::unique_ref<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
|
|
|
|
2015-07-20 18:57:48 +02:00
|
|
|
cpputils::unique_ref<Block> create(const cpputils::Data &data) {
|
|
|
|
while(true) {
|
|
|
|
//TODO Copy (data.copy()) necessary?
|
|
|
|
auto block = tryCreate(createKey(), data.copy());
|
|
|
|
if (block != boost::none) {
|
|
|
|
return std::move(*block);
|
|
|
|
}
|
2015-04-24 13:42:37 +02:00
|
|
|
}
|
2015-04-18 14:47:12 +02:00
|
|
|
}
|
2014-12-09 17:19:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|