Move semantics for FileWriter.

This commit is contained in:
vng 2015-12-04 20:30:43 +03:00 committed by Sergey Yershov
parent 936b9cd747
commit bb1ad91155
3 changed files with 8 additions and 9 deletions

View file

@ -398,7 +398,7 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag)
writer.WritePaddingByPos(kSectionAlignment);
m_info.push_back(Info(tag, writer.Pos()));
ASSERT(m_info.back().m_offset % kSectionAlignment == 0, ());
return writer;
return move(writer);
}
else
{
@ -407,7 +407,7 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag)
writer.WritePaddingByPos(kSectionAlignment);
m_info.push_back(Info(tag, writer.Pos()));
ASSERT(m_info.back().m_offset % kSectionAlignment == 0, ());
return writer;
return move(writer);
}
}

View file

@ -1,10 +1,10 @@
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
FileWriter::FileWriter(FileWriter const & rhs)
: Writer(*this), m_bTruncOnClose(rhs.m_bTruncOnClose)
FileWriter::FileWriter(FileWriter && rhs)
: m_pFileData(move(rhs.m_pFileData)), m_bTruncOnClose(rhs.m_bTruncOnClose)
{
m_pFileData.swap(const_cast<FileWriter &>(rhs).m_pFileData);
}
FileWriter::FileWriter(string const & fileName, FileWriter::Op op, bool bTruncOnClose)

View file

@ -8,6 +8,8 @@ namespace my { class FileData; }
// FileWriter, not thread safe.
class FileWriter : public Writer
{
DISALLOW_COPY(FileWriter);
public:
// Values actually match internal FileData::Op enum.
enum Op
@ -23,9 +25,7 @@ public:
OP_APPEND = 3
};
/// Works like "move semantics".
/// Added for use in FilesContainerW interface.
FileWriter(FileWriter const & rhs);
FileWriter(FileWriter && rhs);
explicit FileWriter(string const & fileName,
Op operation = OP_WRITE_TRUNCATE, bool bTruncOnClose = false);
@ -36,7 +36,6 @@ public:
void Write(void const * p, size_t size);
void WritePaddingByEnd(size_t factor);
void WritePaddingByPos(size_t factor);
uint64_t Size() const;