diff --git a/lib/meson.build b/lib/meson.build index bd661b4c..a2e6e0eb 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -80,11 +80,12 @@ lib_mu=static_library( ], install: false) +# some of the libme headers include xapian +xapian_incs = xapian_dep.get_pkgconfig_variable('includedir') lib_mu_dep = declare_dependency( link_with: lib_mu, - include_directories: include_directories(['.', '..']) -) - + include_directories: + include_directories(['.', '..', xapian_incs])) # # tests diff --git a/lib/mu-msg-doc.cc b/lib/mu-msg-doc.cc index a3ad22b8..c55f2a71 100644 --- a/lib/mu-msg-doc.cc +++ b/lib/mu-msg-doc.cc @@ -30,6 +30,7 @@ #include "utils/mu-str.h" #include "utils/mu-date.h" #include "utils/mu-utils.hh" +#include "utils/mu-xapian-utils.hh" using namespace Mu; @@ -38,7 +39,7 @@ struct Mu::MuMsgDoc { ~MuMsgDoc() { delete _doc; } const Xapian::Document doc() const { return *_doc; } - private: +private: Xapian::Document* _doc; }; diff --git a/lib/mu-query-results.hh b/lib/mu-query-results.hh index 7302e652..84f9636d 100644 --- a/lib/mu-query-results.hh +++ b/lib/mu-query-results.hh @@ -36,6 +36,7 @@ #include #include +#include #include "mu-msg.hh" @@ -157,7 +158,7 @@ operator<<(std::ostream& os, const QueryMatch& qmatch) /// skipped ones do _not_ count towards the max_size /// class QueryResultsIterator { - public: +public: using iterator_category = std::output_iterator_tag; using value_type = MuMsg*; using difference_type = void; @@ -328,7 +329,7 @@ class QueryResultsIterator { (MuMsg*)NULL); } - private: +private: Xapian::MSetIterator mset_it_; QueryMatches& query_matches_; MuMsg* msg_{}; @@ -337,7 +338,7 @@ class QueryResultsIterator { constexpr auto MaxQueryResultsSize = std::numeric_limits::max(); class QueryResults { - public: +public: /// Helper types using iterator = QueryResultsIterator; using const_iterator = const iterator; @@ -391,7 +392,7 @@ class QueryResults { const QueryMatches& query_matches() const { return query_matches_; } QueryMatches& query_matches() { return query_matches_; } - private: +private: const Xapian::MSet mset_; mutable QueryMatches query_matches_; }; diff --git a/lib/mu-store.cc b/lib/mu-store.cc index e1b1a372..4a7c9897 100644 --- a/lib/mu-store.cc +++ b/lib/mu-store.cc @@ -39,6 +39,7 @@ #include "mu-msg-part.hh" #include "utils/mu-utils.hh" +#include "utils/mu-xapian-utils.hh" using namespace Mu; diff --git a/lib/mu-store.hh b/lib/mu-store.hh index 83b22447..8fdeed60 100644 --- a/lib/mu-store.hh +++ b/lib/mu-store.hh @@ -34,14 +34,14 @@ #include namespace Mu { + class Store { - public: +public: 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 * @@ -300,7 +300,7 @@ class Store { std::unique_ptr& priv() { return priv_; } const std::unique_ptr& priv() const { return priv_; } - private: +private: std::unique_ptr priv_; }; diff --git a/lib/utils/Makefile.am b/lib/utils/Makefile.am index 13aa93b9..4ac835bf 100644 --- a/lib/utils/Makefile.am +++ b/lib/utils/Makefile.am @@ -71,6 +71,7 @@ libmu_utils_la_SOURCES= \ mu-util.h \ mu-utils.cc \ mu-utils.hh \ + mu-xapian-utils.hh \ ${third_party} libmu_utils_la_LIBADD= \ diff --git a/lib/utils/meson.build b/lib/utils/meson.build index eb40ff39..d2b28752 100644 --- a/lib/utils/meson.build +++ b/lib/utils/meson.build @@ -36,6 +36,7 @@ lib_mu_utils=static_library('mu-utils', [ 'mu-util.h', 'mu-utils.cc', 'mu-utils.hh', + 'mu-xapian-utils.hh', # third party 'optional.hpp', 'expected.hpp'], diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index cfdb946b..e8c7f2b5 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -29,7 +29,6 @@ #include #include #include -#include namespace Mu { @@ -277,35 +276,6 @@ private: const bool color_; }; -template -void -xapian_try(Func&& func) noexcept -try { - func(); -} catch (const Xapian::Error& xerr) { - g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str()); -} catch (const std::runtime_error& re) { - g_critical("%s: error: %s", __func__, re.what()); -} catch (...) { - g_critical("%s: caught exception", __func__); -} - -template > -auto -xapian_try(Func&& func, Default&& def) noexcept -> std::decay_t -try { - return func(); -} catch (const Xapian::Error& xerr) { - g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str()); - return static_cast(def); -} catch (const std::runtime_error& re) { - g_critical("%s: error: %s", __func__, re.what()); - return static_cast(def); -} catch (...) { - g_critical("%s: caught exception", __func__); - return static_cast(def); -} - /// Allow using enum structs as bitflags #define MU_TO_NUM(ET, ELM) std::underlying_type_t(ELM) #define MU_TO_ENUM(ET, NUM) static_cast(NUM) diff --git a/lib/utils/mu-xapian-utils.hh b/lib/utils/mu-xapian-utils.hh new file mode 100644 index 00000000..4c2d6ba9 --- /dev/null +++ b/lib/utils/mu-xapian-utils.hh @@ -0,0 +1,59 @@ +/* +** Copyright (C) 2021 Dirk-Jan C. Binnema +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of the GNU General Public License as published by the +** Free Software Foundation; either version 3, or (at your option) any +** later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software Foundation, +** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +*/ + +#ifndef MU_XAPIAN_UTILS_HH__ +#define MU_XAPIAN_UTILS_HH__ + +#include + +namespace Mu { + +// avoid exception-handling boilerplate. +template +void +xapian_try(Func&& func) noexcept +try { + func(); +} catch (const Xapian::Error& xerr) { + g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str()); +} catch (const std::runtime_error& re) { + g_critical("%s: error: %s", __func__, re.what()); +} catch (...) { + g_critical("%s: caught exception", __func__); +} + +template > +auto +xapian_try(Func&& func, Default&& def) noexcept -> std::decay_t +try { + return func(); +} catch (const Xapian::Error& xerr) { + g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str()); + return static_cast(def); +} catch (const std::runtime_error& re) { + g_critical("%s: error: %s", __func__, re.what()); + return static_cast(def); +} catch (...) { + g_critical("%s: caught exception", __func__); + return static_cast(def); +} + +} // namespace Mu + +#endif /* MU_ XAPIAN_UTILS_HH__ */