Simplify Data::LoadFromFile and use DISALLOW_COPY_AND_ASSIGN for OnDiskBlob and OnDiskBlobStore

This commit is contained in:
Sebastian Messmer 2014-12-05 08:14:19 +01:00
parent c20b09030d
commit a699350e19
5 changed files with 15 additions and 7 deletions

View File

@ -54,13 +54,13 @@ void Data::StoreToFile(const bf::path &filepath) const {
file.write((const char*)_data, _size);
}
unique_ptr<Data> Data::LoadFromFile(const bf::path &filepath) {
Data Data::LoadFromFile(const bf::path &filepath) {
ifstream file(filepath.c_str(), ios::binary);
size_t size = _getStreamSize(file);
auto blob = make_unique<Data>(size);
blob->_readFromStream(file);
return blob;
Data result(size);
result._readFromStream(file);
return result;
}
size_t Data::_getStreamSize(istream &stream) {

View File

@ -26,7 +26,7 @@ public:
void FillWithZeroes();
void StoreToFile(const boost::filesystem::path &filepath) const;
static std::unique_ptr<Data> LoadFromFile(const boost::filesystem::path &filepath);
static Data LoadFromFile(const boost::filesystem::path &filepath);
private:
size_t _size;

View File

@ -44,9 +44,9 @@ size_t OnDiskBlob::size() const {
}
unique_ptr<OnDiskBlob> OnDiskBlob::LoadFromDisk(const bf::path &filepath) {
auto data = Data::LoadFromFile(filepath);
Data data = Data::LoadFromFile(filepath);
return unique_ptr<OnDiskBlob>(new OnDiskBlob(filepath, std::move(*data.get())));
return unique_ptr<OnDiskBlob>(new OnDiskBlob(filepath, std::move(data)));
}
unique_ptr<OnDiskBlob> OnDiskBlob::CreateOnDisk(const bf::path &filepath, size_t size) {

View File

@ -8,6 +8,8 @@
#include <boost/filesystem/path.hpp>
#include <iostream>
#include "fspp/utils/macros.h"
namespace blobstore {
namespace ondisk {
class OnDiskBlobStore;
@ -34,6 +36,8 @@ private:
static void _assertFileDoesntExist(const boost::filesystem::path &filepath);
void _fillDataWithZeroes();
void _storeToDisk() const;
DISALLOW_COPY_AND_ASSIGN(OnDiskBlob);
};
} /* namespace ondisk */

View File

@ -6,6 +6,8 @@
#include <boost/filesystem/path.hpp>
#include "fspp/utils/macros.h"
namespace blobstore {
namespace ondisk {
class OnDiskBlob;
@ -19,6 +21,8 @@ public:
private:
const boost::filesystem::path _rootdir;
DISALLOW_COPY_AND_ASSIGN(OnDiskBlobStore);
};
} /* namespace ondisk */