lib: replace some #define with constexpr
minor cleanup.
This commit is contained in:
@ -683,7 +683,7 @@ static gchar*
|
||||
get_msgid (MuMsgFile *self, gboolean *do_free)
|
||||
{
|
||||
const char *msgid{g_mime_message_get_message_id (self->_mime_msg)};
|
||||
if (msgid && strlen(msgid) < MU_STORE_MAX_TERM_LENGTH) {
|
||||
if (msgid && strlen(msgid) < Store::MaxTermLength) {
|
||||
*do_free = FALSE;
|
||||
return (char*)msgid;
|
||||
}
|
||||
|
||||
@ -50,9 +50,6 @@
|
||||
using namespace Mu;
|
||||
using namespace Command;
|
||||
|
||||
using DocId = unsigned;
|
||||
|
||||
|
||||
/// @brief object to manage the server-context for all commands.
|
||||
struct Server::Private {
|
||||
Private(Store& store, Output output):
|
||||
@ -116,9 +113,9 @@ private:
|
||||
const Option<QueryMatch&> qm,
|
||||
MuMsgOptions opts);
|
||||
|
||||
Sexp::List move_docid (DocId docid, const std::string& flagstr,
|
||||
Sexp::List move_docid (Store::Id docid, const std::string& flagstr,
|
||||
bool new_name, bool no_view);
|
||||
Sexp::List perform_move (DocId docid, MuMsg *msg,
|
||||
Sexp::List perform_move (Store::Id docid, MuMsg *msg,
|
||||
const std::string& maildirarg,
|
||||
MuFlags flags, bool new_name, bool no_view);
|
||||
|
||||
@ -654,10 +651,10 @@ Server::Private::extract_handler (const Parameters& params)
|
||||
|
||||
|
||||
/* get a *list* of all messages with the given message id */
|
||||
static std::vector<DocId>
|
||||
static std::vector<Store::Id>
|
||||
docids_for_msgid (const Query& q, const std::string& msgid, size_t max=100)
|
||||
{
|
||||
if (msgid.size() > MU_STORE_MAX_TERM_LENGTH - 1) {
|
||||
if (msgid.size() > Store::MaxTermLength) {
|
||||
throw Error(Error::Code::InvalidArgument,
|
||||
"invalid message-id '%s'", msgid.c_str());
|
||||
}
|
||||
@ -677,7 +674,7 @@ docids_for_msgid (const Query& q, const std::string& msgid, size_t max=100)
|
||||
throw Error(Error::Code::NotFound,
|
||||
"could not find message(s) for msgid %s", msgid.c_str());
|
||||
|
||||
std::vector<DocId> docids{};
|
||||
std::vector<Store::Id> docids{};
|
||||
for(auto&& mi: *res)
|
||||
docids.emplace_back(mi.doc_id());
|
||||
|
||||
@ -709,7 +706,7 @@ path_from_docid (const Store& store, unsigned docid)
|
||||
}
|
||||
|
||||
|
||||
static std::vector<DocId>
|
||||
static std::vector<Store::Id>
|
||||
determine_docids (const Query& q, const Parameters& params)
|
||||
{
|
||||
auto docid{get_int_or(params, ":docid", 0)};
|
||||
@ -911,7 +908,7 @@ get_flags (const std::string& path, const std::string& flagstr)
|
||||
}
|
||||
|
||||
Sexp::List
|
||||
Server::Private::perform_move (DocId docid, MuMsg *msg, const std::string& maildirarg,
|
||||
Server::Private::perform_move (Store::Id docid, MuMsg *msg, const std::string& maildirarg,
|
||||
MuFlags flags, bool new_name, bool no_view)
|
||||
{
|
||||
bool different_mdir{};
|
||||
@ -944,10 +941,10 @@ Server::Private::perform_move (DocId docid, MuMsg *msg, const std::string& maild
|
||||
}
|
||||
|
||||
Sexp::List
|
||||
Server::Private::move_docid (DocId docid, const std::string& flagstr,
|
||||
Server::Private::move_docid (Store::Id docid, const std::string& flagstr,
|
||||
bool new_name, bool no_view)
|
||||
{
|
||||
if (docid == MU_STORE_INVALID_DOCID)
|
||||
if (docid == Store::InvalidId)
|
||||
throw Error{Error::Code::InvalidArgument, "invalid docid"};
|
||||
|
||||
auto msg{store_.find_message(docid)};
|
||||
@ -1115,7 +1112,7 @@ Server::Private::sent_handler (const Parameters& params)
|
||||
{
|
||||
const auto path{get_string_or(params, ":path")};
|
||||
const auto docid{store().add_message(path)};
|
||||
if (docid == MU_STORE_INVALID_DOCID)
|
||||
if (docid == Store::InvalidId)
|
||||
throw Error{Error::Code::Store, "failed to add path"};
|
||||
|
||||
Sexp::List lst;
|
||||
@ -1127,11 +1124,11 @@ Server::Private::sent_handler (const Parameters& params)
|
||||
}
|
||||
|
||||
static bool
|
||||
maybe_mark_as_read (Mu::Store& store, MuMsg *msg, DocId docid)
|
||||
maybe_mark_as_read (Mu::Store& store, MuMsg *msg, Store::Id docid)
|
||||
{
|
||||
if (!msg)
|
||||
throw Error{Error::Code::Store, "missing message"};
|
||||
if (docid == MU_STORE_INVALID_DOCID)
|
||||
if (docid == Store::InvalidId)
|
||||
throw Error{Error::Code::Store, "invalid docid"};
|
||||
|
||||
const auto oldflags{mu_msg_get_flags (msg)};
|
||||
@ -1160,7 +1157,7 @@ maybe_mark_as_read (Mu::Store& store, MuMsg *msg, DocId docid)
|
||||
void
|
||||
Server::Private::view_handler (const Parameters& params)
|
||||
{
|
||||
DocId docid{MU_STORE_INVALID_DOCID};
|
||||
Store::Id docid{Store::InvalidId};
|
||||
const auto path{get_string_or(params, ":path")};
|
||||
const auto mark_as_read{get_bool_or(params, ":mark-as-read")};
|
||||
|
||||
|
||||
@ -385,7 +385,7 @@ Store::add_message (const std::string& path)
|
||||
|
||||
const auto docid{priv_->add_or_update_msg (0, msg, &gerr)};
|
||||
mu_msg_unref (msg);
|
||||
if (G_UNLIKELY(docid == MU_STORE_INVALID_DOCID))
|
||||
if (G_UNLIKELY(docid == InvalidId))
|
||||
throw Error{Error::Code::Message, "failed to add message: %s",
|
||||
gerr ? gerr->message : "something went wrong"};
|
||||
|
||||
@ -669,10 +669,10 @@ prio_val (MuMsgPrio prio)
|
||||
static void // add term, truncate if needed.
|
||||
add_term (Xapian::Document& doc, const std::string& term)
|
||||
{
|
||||
if (term.length() < MU_STORE_MAX_TERM_LENGTH)
|
||||
if (term.length() < Store::MaxTermLength)
|
||||
doc.add_term(term);
|
||||
else
|
||||
doc.add_term(term.substr(0, MU_STORE_MAX_TERM_LENGTH));
|
||||
doc.add_term(term.substr(0, Store::MaxTermLength));
|
||||
}
|
||||
|
||||
|
||||
@ -800,7 +800,7 @@ each_part (MuMsg *msg, MuMsgPart *part, PartData *pdata)
|
||||
|
||||
/* save the mime type of any part */
|
||||
if (part->type) {
|
||||
char ctype[MU_STORE_MAX_TERM_LENGTH + 1];
|
||||
char ctype[Store::MaxTermLength + 1];
|
||||
g_snprintf(ctype, sizeof(ctype), "%s/%s", part->type, part->subtype);
|
||||
add_term(pdata->_doc, mime + ctype);
|
||||
}
|
||||
@ -1044,7 +1044,7 @@ update_threading_info (MuMsg *msg, Xapian::Document& doc)
|
||||
Xapian::docid
|
||||
Store::Private::add_or_update_msg (unsigned docid, MuMsg *msg, GError **err)
|
||||
{
|
||||
g_return_val_if_fail (msg, MU_STORE_INVALID_DOCID);
|
||||
g_return_val_if_fail (msg, InvalidId);
|
||||
|
||||
try {
|
||||
Xapian::Document doc (new_doc_from_message(msg));
|
||||
@ -1065,5 +1065,5 @@ Store::Private::add_or_update_msg (unsigned docid, MuMsg *msg, GError **err)
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_G_ERROR (err, MU_ERROR_XAPIAN_STORE_FAILED);
|
||||
|
||||
return MU_STORE_INVALID_DOCID;
|
||||
return InvalidId;
|
||||
}
|
||||
|
||||
@ -35,17 +35,14 @@
|
||||
#include <index/mu-indexer.hh>
|
||||
|
||||
namespace Mu {
|
||||
|
||||
/* http://article.gmane.org/gmane.comp.search.xapian.general/3656 */
|
||||
#define MU_STORE_MAX_TERM_LENGTH (240)
|
||||
#define MU_STORE_INVALID_DOCID 0
|
||||
|
||||
class Store {
|
||||
public:
|
||||
using Id = unsigned; /**< Id for a message in the store (internally,
|
||||
* corresponds to a Xapian document-id) */
|
||||
using Id = Xapian::docid; /**< Id for a message in the store */
|
||||
static constexpr Id InvalidId = 0; /**< Invalid store id */
|
||||
|
||||
static constexpr size_t MaxTermLength = 240; /**< Maximum length of a term,
|
||||
http://article.gmane.org/gmane.comp.search.xapian.general/3656 */
|
||||
|
||||
/**
|
||||
* Construct a store for an existing document database
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user