xapian-core  2.0.0
spymaster.h
Go to the documentation of this file.
1 
4 /* Copyright 2017 Olly Betts
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_SPYMASTER_H
22 #define XAPIAN_INCLUDED_SPYMASTER_H
23 
24 #include <xapian/intrusive_ptr.h>
25 #include <xapian/matchspy.h>
26 
27 #include <vector>
28 
29 class SpyMaster {
31 
33  const std::vector<opt_ptr_spy>* spies;
34 
35  public:
36  explicit SpyMaster(const std::vector<opt_ptr_spy>* spies_)
37  : spies(spies_->empty() ? NULL : spies_)
38  {}
39 
40  operator bool() const { return spies != NULL; }
41 
42  void operator()(const Xapian::Document& doc,
43  double weight) {
44  if (spies != NULL) {
45  for (auto spy : *spies) {
46  (*spy)(doc, weight);
47  }
48  }
49  }
50 };
51 
52 #endif // XAPIAN_INCLUDED_SPYMASTER_H
Xapian::Internal::opt_intrusive_ptr< Xapian::MatchSpy > opt_ptr_spy
Definition: spymaster.h:30
SpyMaster(const std::vector< opt_ptr_spy > *spies_)
Definition: spymaster.h:36
void operator()(const Xapian::Document &doc, double weight)
Definition: spymaster.h:42
const std::vector< opt_ptr_spy > * spies
The MatchSpy objects to apply.
Definition: spymaster.h:33
Class representing a document.
Definition: document.h:64
MatchSpy implementation.