xapian-core  1.4.21
keymaker.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2009,2011,2013,2014,2015,2016 Olly Betts
5  * Copyright (C) 2010 Richard Boulton
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_KEYMAKER_H
23 #define XAPIAN_INCLUDED_KEYMAKER_H
24 
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/keymaker.h> directly; include <xapian.h> instead.
27 #endif
28 
29 #include <string>
30 #include <vector>
31 
32 #include <xapian/intrusive_ptr.h>
33 #include <xapian/types.h>
34 #include <xapian/visibility.h>
35 
36 namespace Xapian {
37 
38 class Document;
39 
44  void operator=(const KeyMaker &);
45 
47  KeyMaker(const KeyMaker &);
48 
49  public:
51  KeyMaker() { }
52 
59  virtual std::string operator()(const Xapian::Document & doc) const = 0;
60 
62  virtual ~KeyMaker();
63 
72  opt_intrusive_base::release();
73  return this;
74  }
75 
83  const KeyMaker * release() const {
84  opt_intrusive_base::release();
85  return this;
86  }
87 };
88 
105  struct KeySpec {
107  bool reverse;
108  std::string defvalue;
109  KeySpec(Xapian::valueno slot_, bool reverse_,
110  const std::string & defvalue_)
111  : slot(slot_), reverse(reverse_), defvalue(defvalue_)
112  {}
113  };
114  std::vector<KeySpec> slots;
115 
116  public:
118 
124  template<class Iterator>
125  MultiValueKeyMaker(Iterator begin, Iterator end) {
126  while (begin != end) add_value(*begin++);
127  }
128 
129  virtual std::string operator()(const Xapian::Document & doc) const;
130 
143  void add_value(Xapian::valueno slot, bool reverse = false,
144  const std::string & defvalue = std::string()) {
145  slots.push_back(KeySpec(slot, reverse, defvalue));
146  }
147 };
148 
149 }
150 
151 #endif // XAPIAN_INCLUDED_KEYMAKER_H
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
MultiValueKeyMaker(Iterator begin, Iterator end)
Construct a MultiValueKeyMaker from a pair of iterators.
Definition: keymaker.h:125
typedefs for Xapian
void add_value(Xapian::valueno slot, bool reverse=false, const std::string &defvalue=std::string())
Add a value slot to the list to build a key from.
Definition: keymaker.h:143
const KeyMaker * release() const
Start reference counting this object.
Definition: keymaker.h:83
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
KeyMaker subclass which combines several values.
Definition: keymaker.h:104
KeySpec(Xapian::valueno slot_, bool reverse_, const std::string &defvalue_)
Definition: keymaker.h:109
Define XAPIAN_VISIBILITY_* macros.
Base class for objects managed by opt_intrusive_ptr.
KeyMaker()
Default constructor.
Definition: keymaker.h:51
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
KeyMaker * release()
Start reference counting this object.
Definition: keymaker.h:71
std::vector< KeySpec > slots
Definition: keymaker.h:114
A handle representing a document in a Xapian database.
Definition: document.h:61
Virtual base class for key making functors.
Definition: keymaker.h:41