2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef BLOCKSTORE_IMPLEMENTATIONS_ONDISK_DATA_H_
|
|
|
|
#define BLOCKSTORE_IMPLEMENTATIONS_ONDISK_DATA_H_
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <boost/filesystem/path.hpp>
|
2015-02-17 00:23:33 +01:00
|
|
|
#include <messmer/cpp-utils/macros.h>
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
|
|
|
|
class Data {
|
|
|
|
public:
|
2015-04-18 14:47:12 +02:00
|
|
|
explicit Data(size_t size);
|
2014-12-09 17:19:59 +01:00
|
|
|
Data(Data &&rhs); // move constructor
|
|
|
|
virtual ~Data();
|
|
|
|
|
2014-12-11 01:41:08 +01:00
|
|
|
Data copy() const;
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
void *data();
|
|
|
|
const void *data() const;
|
|
|
|
|
|
|
|
size_t size() const;
|
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
Data &FillWithZeroes();
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
void StoreToFile(const boost::filesystem::path &filepath) const;
|
|
|
|
static Data LoadFromFile(const boost::filesystem::path &filepath);
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t _size;
|
|
|
|
void *_data;
|
|
|
|
|
|
|
|
static void _assertFileExists(const std::ifstream &file, const boost::filesystem::path &filepath);
|
|
|
|
static size_t _getStreamSize(std::istream &stream);
|
|
|
|
void _readFromStream(std::istream &stream);
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Data);
|
|
|
|
};
|
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
//TODO Test operator==
|
|
|
|
bool operator==(const Data &lhs, const Data &rhs);
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|