message: make it easier to create heap-allocated messages

We need this for guile to coöperate with its garbage collector.
This commit is contained in:
Dirk-Jan C. Binnema
2022-05-21 17:41:21 +03:00
parent 4305f47b86
commit a3ad04f12f
5 changed files with 20 additions and 29 deletions

View File

@ -82,13 +82,13 @@ public:
}
/**
* Construct a message based on a Message::Document
* Construct a message based on a Xapian::Document
*
* @param doc a Mu Document
*
* @return a message or an error
*/
static Result<Message> make_from_document(Mu::Document&& doc) try {
static Result<Message> make_from_document(Xapian::Document&& doc) try {
return Ok(Message{std::move(doc)});
} catch (Error& err) {
return Err(err);
@ -96,17 +96,6 @@ public:
return Err(Mu::Error(Error::Code::Message, "failed to create message"));
}
/**
* Construct a message based on a Xapian::Document
*
* @param doc a xapian document
*
* @return a message or an error
*/
static Result<Message> make_from_document(Xapian::Document&& doc) noexcept {
return make_from_document(Mu::Document{std::move(doc)});
}
/**
* Construct a message from a string. This is mostly useful for testing.
@ -436,13 +425,18 @@ public:
struct Private;
Message(Document&& doc); // XXX: make private
/*
* Usually the make_ builders are better to create a message, but in
* some special cases, we need a heap-allocated message... */
Message(Xapian::Document&& xdoc);
Message(const std::string& path, Options opts);
private:
Message(const std::string& path, Options opts);
Message(const std::string& str, const std::string& path, Options opt);
Message(const std::string& str, const std::string& path, Options opt);
std::unique_ptr<Private> priv_;
std::unique_ptr<Private> priv_;
}; // Message
MU_ENABLE_BITOPS(Message::Options);