mirror of https://github.com/djcb/mu.git
mu: rework xapian dependencies a bit
Reduce the places where we need to include Xapian, and add a few places where the (meson build) didn't explicitly have a Xapian dep where needed.
This commit is contained in:
parent
1c95d28cde
commit
8028f88a51
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include <utils/mu-utils.hh>
|
||||
#include <utils/mu-option.hh>
|
||||
#include <utils/mu-xapian-utils.hh>
|
||||
|
||||
#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<size_t>::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_;
|
||||
};
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "mu-msg-part.hh"
|
||||
#include "utils/mu-utils.hh"
|
||||
#include "utils/mu-xapian-utils.hh"
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
|
|
|
@ -34,14 +34,14 @@
|
|||
#include <index/mu-indexer.hh>
|
||||
|
||||
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<Private>& priv() { return priv_; }
|
||||
const std::unique_ptr<Private>& priv() const { return priv_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unique_ptr<Private> priv_;
|
||||
};
|
||||
|
||||
|
|
|
@ -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= \
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
#include <xapian.h>
|
||||
|
||||
namespace Mu {
|
||||
|
||||
|
@ -277,35 +276,6 @@ private:
|
|||
const bool color_;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
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 <typename Func, typename Default = std::invoke_result<Func>>
|
||||
auto
|
||||
xapian_try(Func&& func, Default&& def) noexcept -> std::decay_t<decltype(func())>
|
||||
try {
|
||||
return func();
|
||||
} catch (const Xapian::Error& xerr) {
|
||||
g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str());
|
||||
return static_cast<Default>(def);
|
||||
} catch (const std::runtime_error& re) {
|
||||
g_critical("%s: error: %s", __func__, re.what());
|
||||
return static_cast<Default>(def);
|
||||
} catch (...) {
|
||||
g_critical("%s: caught exception", __func__);
|
||||
return static_cast<Default>(def);
|
||||
}
|
||||
|
||||
/// Allow using enum structs as bitflags
|
||||
#define MU_TO_NUM(ET, ELM) std::underlying_type_t<ET>(ELM)
|
||||
#define MU_TO_ENUM(ET, NUM) static_cast<ET>(NUM)
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
** Copyright (C) 2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** 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 <xapian.h>
|
||||
|
||||
namespace Mu {
|
||||
|
||||
// avoid exception-handling boilerplate.
|
||||
template <typename Func>
|
||||
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 <typename Func, typename Default = std::invoke_result<Func>>
|
||||
auto
|
||||
xapian_try(Func&& func, Default&& def) noexcept -> std::decay_t<decltype(func())>
|
||||
try {
|
||||
return func();
|
||||
} catch (const Xapian::Error& xerr) {
|
||||
g_critical("%s: xapian error '%s'", __func__, xerr.get_msg().c_str());
|
||||
return static_cast<Default>(def);
|
||||
} catch (const std::runtime_error& re) {
|
||||
g_critical("%s: error: %s", __func__, re.what());
|
||||
return static_cast<Default>(def);
|
||||
} catch (...) {
|
||||
g_critical("%s: caught exception", __func__);
|
||||
return static_cast<Default>(def);
|
||||
}
|
||||
|
||||
} // namespace Mu
|
||||
|
||||
#endif /* MU_ XAPIAN_UTILS_HH__ */
|
Loading…
Reference in New Issue