BlobStoreOnBlocks mirrors BlockStore
This commit is contained in:
parent
532431f8e3
commit
5fee5e862a
@ -1,14 +1,34 @@
|
||||
#include <blobstore/implementations/onblocks/BlobOnBlocks.h>
|
||||
|
||||
using std::unique_ptr;
|
||||
using blockstore::Block;
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
|
||||
BlobOnBlocks::BlobOnBlocks() {
|
||||
BlobOnBlocks::BlobOnBlocks(unique_ptr<Block> block)
|
||||
: _block(std::move(block)) {
|
||||
|
||||
}
|
||||
|
||||
BlobOnBlocks::~BlobOnBlocks() {
|
||||
}
|
||||
|
||||
void *BlobOnBlocks::data() {
|
||||
return const_cast<void*>(const_cast<const BlobOnBlocks*>(this)->data());
|
||||
}
|
||||
|
||||
const void *BlobOnBlocks::data() const {
|
||||
return _block->data();
|
||||
}
|
||||
|
||||
void BlobOnBlocks::flush() {
|
||||
_block->flush();
|
||||
}
|
||||
|
||||
size_t BlobOnBlocks::size() const {
|
||||
return _block->size();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,28 @@
|
||||
#ifndef BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_BLOBONBLOCKS_H_
|
||||
#define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_BLOBONBLOCKS_H_
|
||||
|
||||
#include "blobstore/interface/Blob.h"
|
||||
#include "blockstore/interface/Block.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
|
||||
class BlobOnBlocks {
|
||||
class BlobOnBlocks: public Blob {
|
||||
public:
|
||||
BlobOnBlocks();
|
||||
BlobOnBlocks(std::unique_ptr<blockstore::Block> block);
|
||||
virtual ~BlobOnBlocks();
|
||||
|
||||
void *data() override;
|
||||
const void *data() const override;
|
||||
|
||||
void flush() override;
|
||||
|
||||
size_t size() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<blockstore::Block> _block;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,30 @@
|
||||
#include <blobstore/implementations/onblocks/BlobStoreOnBlocks.h>
|
||||
#include "BlobStoreOnBlocks.h"
|
||||
|
||||
#include "BlobOnBlocks.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
|
||||
using blockstore::BlockStore;
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
|
||||
BlobStoreOnBlocks::BlobStoreOnBlocks() {
|
||||
BlobStoreOnBlocks::BlobStoreOnBlocks(unique_ptr<BlockStore> blockStore)
|
||||
: _blocks(std::move(blockStore)) {
|
||||
}
|
||||
|
||||
BlobStoreOnBlocks::~BlobStoreOnBlocks() {
|
||||
}
|
||||
|
||||
BlobWithKey BlobStoreOnBlocks::create(size_t size) {
|
||||
auto block = _blocks->create(size);
|
||||
return BlobWithKey(block.key, make_unique<BlobOnBlocks>(std::move(block.block)));
|
||||
}
|
||||
|
||||
unique_ptr<Blob> BlobStoreOnBlocks::load(const std::string &key) {
|
||||
return make_unique<BlobOnBlocks>(_blocks->load(key));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,22 @@
|
||||
#ifndef BLOBSTORE_IMPLEMENTATIONS_BLOCKED_BLOBSTOREONBLOCKS_H_
|
||||
#define BLOBSTORE_IMPLEMENTATIONS_BLOCKED_BLOBSTOREONBLOCKS_H_
|
||||
|
||||
#include "blobstore/interface/BlobStore.h"
|
||||
#include "blockstore/interface/BlockStore.h"
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
|
||||
class BlobStoreOnBlocks {
|
||||
class BlobStoreOnBlocks: public BlobStore {
|
||||
public:
|
||||
BlobStoreOnBlocks();
|
||||
BlobStoreOnBlocks(std::unique_ptr<blockstore::BlockStore> blockStore);
|
||||
virtual ~BlobStoreOnBlocks();
|
||||
|
||||
BlobWithKey create(size_t size) override;
|
||||
std::unique_ptr<Blob> load(const std::string &key) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<blockstore::BlockStore> _blocks;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,10 +9,10 @@
|
||||
namespace blobstore {
|
||||
|
||||
struct BlobWithKey {
|
||||
BlobWithKey(const std::string &key_, std::unique_ptr<Blocb> blob_): key(key_), blob(std::move(blob_)) {}
|
||||
BlobWithKey(const std::string &key_, std::unique_ptr<Blob> blob_): key(key_), blob(std::move(blob_)) {}
|
||||
|
||||
std::string key;
|
||||
std::unique_ptr<Block> blob;
|
||||
std::unique_ptr<Blob> blob;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user