[ci] Fix clang-santisers job for GHA change
[xapian.git] / xapian-core / include / xapian / expanddecider.h
blob3b39e23bde8caff627708205b3cab804feb4a531
1 /** @file
2 * @brief Allow rejection of terms during ESet generation.
3 */
4 /* Copyright (C) 2007,2011,2013,2014,2015,2016 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef XAPIAN_INCLUDED_EXPANDDECIDER_H
22 #define XAPIAN_INCLUDED_EXPANDDECIDER_H
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/expanddecider.h> directly; include <xapian.h> instead.
26 #endif
28 #include <set>
29 #include <string>
31 #include <xapian/intrusive_ptr.h>
32 #include <xapian/visibility.h>
34 namespace Xapian {
36 /** Virtual base class for expand decider functor. */
37 class XAPIAN_VISIBILITY_DEFAULT ExpandDecider
38 : public Xapian::Internal::opt_intrusive_base {
39 /// Don't allow assignment.
40 void operator=(const ExpandDecider &) = delete;
42 /// Don't allow copying.
43 ExpandDecider(const ExpandDecider &) = delete;
45 public:
46 /// Default constructor.
47 ExpandDecider() { }
49 /** Do we want this term in the ESet?
51 * @param term The term to test.
53 virtual bool operator()(const std::string &term) const = 0;
55 /** Virtual destructor, because we have virtual methods. */
56 virtual ~ExpandDecider();
58 /** Start reference counting this object.
60 * You can transfer ownership of a dynamically allocated ExpandDecider
61 * object to Xapian by calling release() and then passing the object to a
62 * Xapian method. Xapian will arrange to delete the object once it is no
63 * longer required.
65 ExpandDecider * release() {
66 opt_intrusive_base::release();
67 return this;
70 /** Start reference counting this object.
72 * You can transfer ownership of a dynamically allocated ExpandDecider
73 * object to Xapian by calling release() and then passing the object to a
74 * Xapian method. Xapian will arrange to delete the object once it is no
75 * longer required.
77 const ExpandDecider * release() const {
78 opt_intrusive_base::release();
79 return this;
83 /** ExpandDecider subclass which rejects terms using two ExpandDeciders.
85 * Terms are only accepted if they are accepted by both of the specified
86 * ExpandDecider objects.
88 class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderAnd : public ExpandDecider {
89 Internal::opt_intrusive_ptr<const ExpandDecider> first, second;
91 public:
92 /** Terms will be checked with @a first, and if accepted, then checked
93 * with @a second.
95 * @param first_ First ExpandDecider object to test with.
96 * @param second_ ExpandDecider object to test with if first_ accepts.
98 ExpandDeciderAnd(const ExpandDecider &first_,
99 const ExpandDecider &second_)
100 : first(&first_), second(&second_) { }
102 /** Compatibility method.
104 * @param first_ First ExpandDecider object to test with.
105 * @param second_ ExpandDecider object to test with if first_ accepts.
107 ExpandDeciderAnd(const ExpandDecider *first_,
108 const ExpandDecider *second_)
109 : first(first_), second(second_) { }
111 virtual bool operator()(const std::string &term) const;
114 /** ExpandDecider subclass which rejects terms in a specified list.
116 * ExpandDeciderFilterTerms provides an easy way to filter out terms from
117 * a fixed list when generating an ESet.
119 class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderFilterTerms : public ExpandDecider {
120 std::set<std::string> rejects;
122 public:
123 /** The two iterators specify a list of terms to be rejected.
125 * @param reject_begin Begin iterator for the list of terms to
126 * reject. It can be any input_iterator type
127 * which returns std::string or char * (e.g.
128 * TermIterator or char **).
129 * @param reject_end End iterator for the list of terms to reject.
131 template<class Iterator>
132 ExpandDeciderFilterTerms(Iterator reject_begin, Iterator reject_end)
133 : rejects(reject_begin, reject_end) { }
135 virtual bool operator()(const std::string &term) const;
138 /** ExpandDecider subclass which restrict terms to a particular prefix
140 * ExpandDeciderFilterPrefix provides an easy way to choose terms with a
141 * particular prefix when generating an ESet.
143 class XAPIAN_VISIBILITY_DEFAULT ExpandDeciderFilterPrefix : public ExpandDecider {
144 std::string prefix;
146 public:
147 /** The parameter specify the prefix of terms to be retained
148 * @param prefix_ restrict terms to the particular prefix_
150 explicit ExpandDeciderFilterPrefix(const std::string &prefix_)
151 : prefix(prefix_) { }
153 virtual bool operator() (const std::string &term) const;
158 #endif // XAPIAN_INCLUDED_EXPANDDECIDER_H