Skip to content

Commit

Permalink
gcc-4.9 fix
Browse files Browse the repository at this point in the history
Sadly libstdc++ before v5 doesn't support moving a stringstream, so work
around it by passing a unique_ptr instead.
  • Loading branch information
jagerman committed Oct 27, 2016
1 parent 1e8a5a3 commit e032ff8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions eris/serialize/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ void Serialization::memory() {
writeHeader();
}

void Serialization::memory(std::stringstream &&str, Mode mode) {

void Serialization::memory(std::unique_ptr<std::stringstream> &&str, Mode mode) {
close();
f_ = std::move(str);
if (!f_) throw std::runtime_error("Serialization::memory(...) called with a null unique ptr");

f_.reset(new std::stringstream(std::move(str)));
f_->exceptions(f_->failbit | f_->badbit);
if (mode == Mode::OVERWRITE) throw std::logic_error("Serialization::memory(ss, mode) called with invalid mode: Mode::OVERWRITE");
read_only_ = mode == Mode::READONLY;
Expand Down
10 changes: 7 additions & 3 deletions eris/serialize/Serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,16 @@ class Serialization {
*
* If an existing file (or memory buffer) is open, it will be closed (or discarded).
*
* \param s the existing stringstream to use for storage. If the stream contains existing
* XZ-compressed data, that data will be decompressed into a new stringstream.
* \param s a unique_ptr to the existing stringstream to use for storage. The Serialization
* object takes over management of the pointer (i.e. the caller should not keep it). If the
* stream contains existing XZ-compressed data, that data will be decompressed into a new
* stringstream.
* \param mode the mode of the resulting buffer. Mode::OVERWRITE may not be used. Defaults to
* Mode::READONLY.
*/
void memory(std::stringstream &&s, Mode mode = Mode::READONLY);
void memory(std::unique_ptr<std::stringstream> &&s, Mode mode = Mode::READONLY);
// NB: the above would be much nicer if it just took a std::stringstream&&, but stringstreams
// are not move constructible in gcc (actually libstdc++) before 5.0.

/** Returns true if close() may take time due to required copying and/or compression. Returns
* false if results have been written directly to the final (uncompressed) file, or if no
Expand Down

0 comments on commit e032ff8

Please sign in to comment.