2015-03-04 20:47:02 +01:00
|
|
|
#include "../interface/BlockStore.h"
|
|
|
|
#include "BlockStoreUtils.h"
|
2015-04-25 02:48:41 +02:00
|
|
|
#include <messmer/cpp-utils/data/Data.h>
|
2015-02-22 19:29:30 +01:00
|
|
|
#include <cassert>
|
2015-07-22 13:42:07 +02:00
|
|
|
#include <messmer/cpp-utils/assert/assert.h>
|
2015-01-24 01:24:37 +01:00
|
|
|
|
2015-04-25 02:48:41 +02:00
|
|
|
using cpputils::Data;
|
2015-07-20 18:57:48 +02:00
|
|
|
using cpputils::unique_ref;
|
2015-01-24 01:24:37 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace utils {
|
|
|
|
|
2015-07-20 18:57:48 +02:00
|
|
|
unique_ref<Block> copyToNewBlock(BlockStore *blockStore, const Block &block) {
|
2015-04-18 14:47:12 +02:00
|
|
|
Data data(block.size());
|
|
|
|
std::memcpy(data.data(), block.data(), block.size());
|
|
|
|
return blockStore->create(data);
|
2015-01-24 01:24:37 +01:00
|
|
|
}
|
|
|
|
|
2015-02-22 19:29:30 +01:00
|
|
|
void copyTo(Block *target, const Block &source) {
|
2015-07-22 13:42:07 +02:00
|
|
|
ASSERT(target->size() == source.size(), "Can't copy block data when blocks have different sizes");
|
2015-03-04 20:47:02 +01:00
|
|
|
target->write(source.data(), 0, source.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void fillWithZeroes(Block *target) {
|
|
|
|
Data zeroes(target->size());
|
|
|
|
zeroes.FillWithZeroes();
|
|
|
|
target->write(zeroes.data(), 0, target->size());
|
2015-02-22 19:29:30 +01:00
|
|
|
}
|
|
|
|
|
2015-01-24 01:24:37 +01:00
|
|
|
}
|
|
|
|
}
|