clang-format: update c/cc coding style

Update all cc code using .clang-format; please do so as well for future PRs
etc.; emacs has a handy 'clang-format' mode to make this automatic.

For comparing old changes with git blame, we can disregard this one using
--ignore-rev

(see https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame )
This commit is contained in:
Dirk-Jan C. Binnema
2021-10-20 12:18:15 +03:00
parent 09935cc4b3
commit 3dd721d5a3
111 changed files with 13851 additions and 14579 deletions

View File

@ -29,37 +29,29 @@
namespace Mu {
struct QueryMatchInfo {
enum struct Flags {
Seen,
Preferred,
Unreadable,
Duplicate
};
const std::string message_id;
QueryMatchFlags flags;
enum struct Flags { Seen, Preferred, Unreadable, Duplicate };
const std::string message_id;
QueryMatchFlags flags;
};
MU_ENABLE_BITOPS(QueryMatchInfo::Flags);
using MatchInfo = std::unordered_map<Xapian::docid, QueryMatchInfo>;
struct QueryResults {
enum struct Flags {
None,
Descending,
SkipUnreadable,
SkipDups,
DetermineThreads
};
enum struct Flags { None, Descending, SkipUnreadable, SkipDups, DetermineThreads };
QueryResults (const Xapian::MSet& mset, MatchInfo&& match_info, Flags flags):
QueryResults (const Xapian::MSet& mset, MatchInfo&& match_info, Flags flags):
mset_{mset}, match_info_(std::Move(match_info), flag_{flags} {}
bool empty() const { return mset_.empty(); }
size_t size() const { return mset_.size(); }
bool empty() const {
return mset_.empty(); }
size_t size() const {
return mset_.size(); }
QueryResultsIterator begin() const { return QueryResultsIterator(mset_.begin()); }
QueryResultsIterator end() const { return QueryResultsIterator(mset_.end()); }
QueryResultsIterator begin() const {
return QueryResultsIterator(mset_.begin()); }
QueryResultsIterator end() const {
return QueryResultsIterator(mset_.end()); }
private:
const Xapian::MSet mset_;
@ -72,135 +64,148 @@ private:
/// unreadable / duplicate messages.
///
class QueryResultsIterator {
public:
using iterator_category = std::output_iterator_tag;
using value_type = MuMsg*;
using difference_type = void;
using pointer = void;
using reference = void;
public:
using iterator_category = std::output_iterator_tag;
using value_type = MuMsg*;
using difference_type = void;
using pointer = void;
using reference = void;
QueryResultsIterator(Xapian::MSetIterator it, size_t max_num,
MuMsgFieldId sort_field, MuMsgIterFlags flags,
MatchInfo& minfo):
it_{it}, match_info_{minfo} {}
QueryResultsIterator(Xapian::MSetIterator it,
size_t max_num,
MuMsgFieldId sort_field,
MuMsgIterFlags flags,
MatchInfo& minfo)
: it_{it}, match_info_{minfo}
{
}
QueryResultsIterator& operator++() { return ++it_; return skip();}
QueryResultsIterator& operator++(int) { return it_++; return skip()}
QueryResultsIterator& operator++()
{
return ++it_;
return skip();
}
QueryResultsIterator& operator++(int)
{
return it_++;
return skip()
}
/**
* Get the Xapian document this iterator is pointing at,
* or an empty document when looking at end().
*
* @return a document
*/
Xapian::Document document() const() {
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), {});
return it_.get_document();
}
/**
* Get the Xapian document this iterator is pointing at,
* or an empty document when looking at end().
*
* @return a document
*/
Xapian::Document document() const()
{
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), {});
return it_.get_document();
}
/**
* Get the doc-id for the document this iterator is pointing at, or 0
* when looking at end.
*
* @return a doc-id.
*/
Xapian::docid doc_id() const {
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), 0);
return it_.docid();
}
/**
* Get the doc-id for the document this iterator is pointing at, or 0
* when looking at end.
*
* @return a doc-id.
*/
Xapian::docid doc_id() const
{
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), 0);
return it_.docid();
}
/**
* Get the message-id for the document (message) this iterator is
* pointing at, or "" when looking at end.
*
* @return a message-id
*/
std::string message_id() const {
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), "");
return document().get_value(MU_MSG_FIELD_ID_MSGID);
}
/**
* Get the message-id for the document (message) this iterator is
* pointing at, or "" when looking at end.
*
* @return a message-id
*/
std::string message_id() const
{
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), "");
return document().get_value(MU_MSG_FIELD_ID_MSGID);
}
/**
* Get the file-system path for the document (message) this iterator is
* pointing at, or "" when looking at end.
*
* @return a filesystem path
*/
std::string path() const {
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), "");
return document().get_value(MU_MSG_FIELD_ID_PATH);
}
/**
* Get the file-system path for the document (message) this iterator is
* pointing at, or "" when looking at end.
*
* @return a filesystem path
*/
std::string path() const
{
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), "");
return document().get_value(MU_MSG_FIELD_ID_PATH);
}
/**
* Get the references for the document (messages) this is iterator is
* pointing at, or empty if pointing at end of if no references are
* available.
*
* @return references
*/
std::vector<std::string> references() const {
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), {});
return split(document().get_value(MU_MSG_FIELD_ID_REFS), ",");
}
/**
* Get the references for the document (messages) this is iterator is
* pointing at, or empty if pointing at end of if no references are
* available.
*
* @return references
*/
std::vector<std::string> references() const
{
g_return_val_if_fail(it_ != Xapian::MSetIterator::end(), {});
return split(document().get_value(MU_MSG_FIELD_ID_REFS), ",");
}
private:
/**
* Filter out some documents
*
* @param forward whether to skip forward when a document is filtered
* out.
*
* @return the first iterator that is not filtered out, or the end
* iterator.
*/
QueryResultsIterator& maybe_skip(bool forward=true) {
private:
/**
* Filter out some documents
*
* @param forward whether to skip forward when a document is filtered
* out.
*
* @return the first iterator that is not filtered out, or the end
* iterator.
*/
QueryResultsIterator& maybe_skip(bool forward = true)
{
if (it_ = MSetIterator::end())
return *this; // nothing to do.
if (it_ = MSetIterator::end())
return *this; // nothing to do.
// Find or create MatchInfo
const auto msgid{message_id()};
auto mi=[&] {
// Find or create MatchInfo
const auto msgid{message_id()};
auto mi = [&] {
// seen before?
auto m{match_info_.find(docid)};
if (m != match_info_.end())
return m;
// nope; create.
QueryMatchInfo minfo { message_id() };
QueryMatchInfo minfo{message_id()};
// not seen before; check.
if (any_of(flags_ & SkipDups) &&
match_info_.count(message_id()))
if (any_of(flags_ & SkipDups) && match_info_.count(message_id()))
minfo.flags |= Flags::Duplicate; // it's a duplicate
if (any_of(flags_ & SkipUnreadable) &&
::access(path().c_str(), R_OK) != 0)
if (any_of(flags_ & SkipUnreadable) && ::access(path().c_str(), R_OK) != 0)
minfo.flags |= Flags::Unreadable;
return match_info_.emplace_back(std::move(minfo));
}();
}();
// note: SkipDups / SkipUnreadable are not set if
// if we're not checking for those.
// note: SkipDups / SkipUnreadable are not set if
// if we're not checking for those.
if (any_of(mi->second.flags_ & SkipDups) ||
any_of(mi->second.flags_ & SkipUnreadable)) {
if (forward)
++it_;
else
--it_;
if (any_of(mi->second.flags_ & SkipDups) ||
any_of(mi->second.flags_ & SkipUnreadable)) {
if (forward)
++it_;
else
--it_;
return maybe_skip();
}
return maybe_skip();
}
return *this;
}
return *this;
}
Xapian::MSetIterator it_;
MatchInfo& match_info_;
Xapian::MSetIterator it_;
MatchInfo& match_info_;
};
}; // namespace Mu
#endif /* MU_QUERY_MATCHES_HH__ */