From 2aa299b3ac14836239906a057fad818a65e05521 Mon Sep 17 00:00:00 2001 From: djcb Date: Sun, 11 Nov 2018 12:11:06 +0200 Subject: [PATCH] mu: add mu_msg_iter_is_(first|last) This makes it a bit easier to process the output. --- lib/mu-msg-iter.cc | 30 ++++++++++++++++++------------ lib/mu-msg-iter.h | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/mu-msg-iter.cc b/lib/mu-msg-iter.cc index 5f811d4d..f74804bf 100644 --- a/lib/mu-msg-iter.cc +++ b/lib/mu-msg-iter.cc @@ -37,7 +37,6 @@ #include "mu-msg-iter.h" #include "mu-threader.h" - struct ltstr { bool operator () (const std::string &s1, const std::string &s2) const { @@ -135,7 +134,6 @@ public: return doc.get_docid(); } - bool looks_like_dup () const { try { const Xapian::Document doc (cursor().get_document()); @@ -201,7 +199,6 @@ private: bool _skip_dups; }; - static gboolean is_msg_file_readable (MuMsgIter *iter) { @@ -217,8 +214,7 @@ is_msg_file_readable (MuMsgIter *iter) } - -MuMsgIter * +MuMsgIter* mu_msg_iter_new (XapianEnquire *enq, size_t maxnum, MuMsgFieldId sortfield, MuMsgIterFlags flags, GError **err) @@ -255,8 +251,6 @@ mu_msg_iter_destroy (MuMsgIter *iter) try { delete iter; } MU_XAPIAN_CATCH_BLOCK; } - - void mu_msg_iter_set_preferred (MuMsgIter *iter, GHashTable *preferred_hash) { @@ -264,8 +258,6 @@ mu_msg_iter_set_preferred (MuMsgIter *iter, GHashTable *preferred_hash) iter->set_preferred_map (preferred_hash); } - - MuMsg* mu_msg_iter_get_msg_floating (MuMsgIter *iter) { @@ -342,7 +334,24 @@ mu_msg_iter_is_done (MuMsgIter *iter) } MU_XAPIAN_CATCH_BLOCK_RETURN (TRUE); } +gboolean +mu_msg_iter_is_first (MuMsgIter *iter) +{ + g_return_val_if_fail (iter, FALSE); + return iter->cursor() == iter->matches().begin(); +} + +gboolean +mu_msg_iter_is_last (MuMsgIter *iter) +{ + g_return_val_if_fail (iter, FALSE); + + if (mu_msg_iter_is_done (iter)) + return FALSE; + + return iter->cursor() + 1 == iter->matches().end(); +} /* hmmm.... is it impossible to get a 0 docid, or just very improbable? */ unsigned @@ -358,7 +367,6 @@ mu_msg_iter_get_docid (MuMsgIter *iter) } - char* mu_msg_iter_get_msgid (MuMsgIter *iter) { @@ -371,7 +379,6 @@ mu_msg_iter_get_msgid (MuMsgIter *iter) } MU_XAPIAN_CATCH_BLOCK_RETURN (NULL); } - char** mu_msg_iter_get_refs (MuMsgIter *iter) { @@ -402,7 +409,6 @@ mu_msg_iter_get_thread_id (MuMsgIter *iter) } MU_XAPIAN_CATCH_BLOCK_RETURN (NULL); } - const MuMsgIterThreadInfo* mu_msg_iter_get_thread_info (MuMsgIter *iter) { diff --git a/lib/mu-msg-iter.h b/lib/mu-msg-iter.h index 95a79ca2..224cd04f 100644 --- a/lib/mu-msg-iter.h +++ b/lib/mu-msg-iter.h @@ -83,6 +83,24 @@ MuMsgIter *mu_msg_iter_new (XapianEnquire *enq, */ gboolean mu_msg_iter_next (MuMsgIter *iter); +/** + * Does this iterator point to the first item? + * + * @param iter a valid MuMsgIter iterator + * + * @return TRUE or FALSE + */ +gboolean mu_msg_iter_is_first (MuMsgIter *iter); + +/** + * Does this iterator point to the last item? + * + * @param iter a valid MuMsgIter iterator + * + * @return TRUE or FALSE + */ +gboolean mu_msg_iter_is_last (MuMsgIter *iter); + /** * reset the iterator to the beginning @@ -124,8 +142,6 @@ void mu_msg_iter_destroy (MuMsgIter *iter); MuMsg* mu_msg_iter_get_msg_floating (MuMsgIter *iter) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; - - /** * Provide a preferred_hash, which is a hashtable msgid->docid to * indicate the messages which should /not/ be seen as duplicates. @@ -136,8 +152,6 @@ MuMsg* mu_msg_iter_get_msg_floating (MuMsgIter *iter) */ void mu_msg_iter_set_preferred (MuMsgIter *iter, GHashTable *preferred_hash); - - /** * get the document id for the current message * @@ -190,8 +204,6 @@ typedef struct _MuMsgIterThreadInfo MuMsgIterThreadInfo; */ const MuMsgIterThreadInfo* mu_msg_iter_get_thread_info (MuMsgIter *iter); - - /** * get the message-id for this message *