message: add move constructor

This commit is contained in:
Dirk-Jan C. Binnema 2022-04-22 08:08:51 +03:00
parent 4a135e70fb
commit f0bfb38ff2
2 changed files with 33 additions and 8 deletions

View File

@ -129,13 +129,28 @@ Message::Message(Message::Options opts, const std::string& text, const std::stri
fill_document(*priv_);
}
Message::Message(Message&& msg) = default;
Message::Message(Document& doc):
Message::Message(Message&& other) noexcept
{
*this = std::move(other);
}
Message&
Message::operator=(Message&& other) noexcept
{
if (this != &other)
priv_ = std::move(other.priv_);
return *this;
}
Message::Message(Document&& doc):
priv_{std::make_unique<Private>()}
{
priv_->doc = doc;
priv_->doc = std::move(doc);
}
Message::~Message() = default;
const Mu::Document&

View File

@ -52,7 +52,17 @@ public:
*
* @param some other message
*/
Message(Message&& msg);
Message(Message&& other) noexcept;
/**
* operator=
*
* @param other move some object object
*
* @return
*/
Message& operator=(Message&& other) noexcept;
/**
* Construct a message based on a path. The maildir is optional; however
@ -85,14 +95,15 @@ public:
*
* @return a message or an error
*/
static Result<Message> make_from_document(Document& doc) try {
return Ok(Message{doc});
static Result<Message> make_from_document(Xapian::Document&& doc) try {
return Ok(Message{Mu::Document{std::move(doc)}});
} catch (Error& err) {
return Err(err);
} catch (...) {
return Err(Mu::Error(Error::Code::Message, "failed to create message"));
}
/**
* Construct a message from a string. This is mostly useful for testing.
*
@ -340,13 +351,12 @@ public:
*/
bool has_mime_message() const;
struct Private;
private:
Message(Options opts, const std::string& path, const std::string& mdir);
Message(Options opts, const std::string& str, const std::string& path,
const std::string& mdir);
Message(Document& doc);
Message(Document&& doc);
std::unique_ptr<Private> priv_;
}; // Message