2015-04-15 19:05:58 +02:00
|
|
|
#pragma once
|
2015-10-15 13:09:21 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEDBLOCK_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEDBLOCK_H_
|
2015-04-15 19:05:58 +02:00
|
|
|
|
|
|
|
#include "../../interface/Block.h"
|
|
|
|
|
2015-07-21 14:50:52 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-04-15 19:05:58 +02:00
|
|
|
|
|
|
|
namespace blockstore {
|
2015-04-16 14:10:44 +02:00
|
|
|
namespace caching {
|
|
|
|
class CachingBlockStore;
|
2015-04-15 19:05:58 +02:00
|
|
|
|
2015-11-27 14:06:40 +01:00
|
|
|
class CachedBlock final: public Block {
|
2015-04-15 19:05:58 +02:00
|
|
|
public:
|
|
|
|
//TODO Storing key twice (in parent class and in object pointed to). Once would be enough.
|
2015-07-21 14:50:52 +02:00
|
|
|
CachedBlock(cpputils::unique_ref<Block> baseBlock, CachingBlockStore *blockStore);
|
2015-11-27 14:06:40 +01:00
|
|
|
~CachedBlock();
|
2015-04-15 19:05:58 +02:00
|
|
|
|
|
|
|
const void *data() const override;
|
|
|
|
void write(const void *source, uint64_t offset, uint64_t size) override;
|
|
|
|
void flush() override;
|
|
|
|
|
|
|
|
size_t size() const override;
|
|
|
|
|
2015-07-21 14:50:52 +02:00
|
|
|
cpputils::unique_ref<Block> releaseBlock();
|
2015-04-15 20:39:58 +02:00
|
|
|
|
2015-04-15 19:05:58 +02:00
|
|
|
private:
|
2015-04-16 14:10:44 +02:00
|
|
|
CachingBlockStore *_blockStore;
|
2015-07-21 14:50:52 +02:00
|
|
|
cpputils::unique_ref<Block> _baseBlock;
|
2015-04-15 19:05:58 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CachedBlock);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|