Add Data::LoadFromStream(stream, size)
This commit is contained in:
parent
ea30ac641b
commit
f88221a0c6
@ -31,9 +31,7 @@ std::streampos Data::_getStreamSize(istream &stream) {
|
||||
return endpos - current_pos;
|
||||
}
|
||||
|
||||
Data Data::LoadFromStream(istream &stream) {
|
||||
size_t size = _getStreamSize(stream);
|
||||
|
||||
Data Data::LoadFromStream(istream &stream, size_t size) {
|
||||
Data result(size);
|
||||
stream.read(static_cast<char*>(result.data()), result.size());
|
||||
return std::move(result);
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
|
||||
//TODO Test LoadFromStream/StoreToStream
|
||||
static Data LoadFromStream(std::istream &stream);
|
||||
static Data LoadFromStream(std::istream &stream, size_t size);
|
||||
void StoreToStream(std::ostream &stream) const;
|
||||
|
||||
private:
|
||||
@ -122,11 +123,14 @@ inline void Data::StoreToFile(const boost::filesystem::path &filepath) const {
|
||||
StoreToStream(file);
|
||||
}
|
||||
|
||||
|
||||
inline void Data::StoreToStream(std::ostream &stream) const {
|
||||
stream.write(static_cast<const char*>(_data), _size);
|
||||
}
|
||||
|
||||
inline Data Data::LoadFromStream(std::istream &stream) {
|
||||
return LoadFromStream(stream, _getStreamSize(stream));
|
||||
}
|
||||
|
||||
inline bool operator==(const Data &lhs, const Data &rhs) {
|
||||
return lhs.size() == rhs.size() && 0 == memcmp(lhs.data(), rhs.data(), lhs.size());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user