xapian-core  1.4.26
termiterator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,2010,2011,2012,2013,2014,2015,2023 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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19  * USA
20  */
21 
22 #ifndef XAPIAN_INCLUDED_TERMITERATOR_H
23 #define XAPIAN_INCLUDED_TERMITERATOR_H
24 
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/termiterator.h> directly; include <xapian.h> instead.
27 #endif
28 
29 #include <iterator>
30 #include <string>
31 
32 #include <xapian/attributes.h>
33 #include <xapian/derefwrapper.h>
35 #include <xapian/types.h>
36 #include <xapian/visibility.h>
37 
38 namespace Xapian {
39 
42  public:
44  class Internal;
46  Internal * internal;
47 
49  explicit TermIterator(Internal *internal_);
50 
52  TermIterator(const TermIterator & o);
53 
55  TermIterator & operator=(const TermIterator & o);
56 
57 #ifdef XAPIAN_MOVE_SEMANTICS
60  : internal(o.internal) {
61  o.internal = nullptr;
62  }
63 
65  TermIterator & operator=(TermIterator && o) {
66  if (this != &o) {
67  if (internal) decref();
68  internal = o.internal;
69  o.internal = nullptr;
70  }
71  return *this;
72  }
73 #endif
74 
80  XAPIAN_NOTHROW(TermIterator())
81  : internal() { }
82 
85  if (internal) decref();
86  }
87 
89  std::string operator*() const;
90 
92  Xapian::termcount get_wdf() const;
93 
101  Xapian::doccount get_termfreq() const;
102 
104  Xapian::termcount positionlist_count() const;
105 
107  PositionIterator positionlist_begin() const;
108 
110  PositionIterator XAPIAN_NOTHROW(positionlist_end() const) {
111  return PositionIterator();
112  }
113 
115  TermIterator & operator++();
116 
119  const std::string & term(**this);
120  operator++();
121  return DerefWrapper_<std::string>(term);
122  }
123 
133  void skip_to(const std::string &term);
134 
136  std::string get_description() const;
137 
148  // @{
150  typedef std::input_iterator_tag iterator_category;
152  typedef std::string value_type;
156  typedef std::string * pointer;
158  typedef std::string & reference;
159  // @}
160 
161  private:
162  void decref();
163 
164  void post_advance(Internal * res);
165 };
166 
167 bool
168 XAPIAN_NOTHROW(operator==(const TermIterator &a, const TermIterator &b));
169 
171 inline bool
173 {
174  // Use a pointer comparison - this ensures both that (a == a) and correct
175  // handling of end iterators (which we ensure have NULL internals).
176  return a.internal == b.internal;
177 }
178 
179 bool
180 XAPIAN_NOTHROW(operator!=(const TermIterator &a, const TermIterator &b));
181 
183 inline bool
185 {
186  return !(a == b);
187 }
188 
189 }
190 
191 #endif // XAPIAN_INCLUDED_TERMITERATOR_H
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
DerefWrapper_< std::string > operator++(int)
Advance the iterator to the next position (postfix version).
Definition: termiterator.h:118
typedefs for Xapian
std::string * pointer
Definition: termiterator.h:156
Compiler attribute macros.
bool operator!=(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:287
Abstract base class for termlists.
Definition: termlist.h:39
bool operator==(const ESetIterator &a, const ESetIterator &b)
Equality test for ESetIterator objects.
Definition: eset.h:277
Class for iterating over term positions.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
~TermIterator()
Destructor.
Definition: termiterator.h:84
Class for iterating over a list of terms.
Definition: termiterator.h:41
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
PositionIterator positionlist_end() const
Return an end PositionIterator for the current term.
Definition: termiterator.h:110
std::string & reference
Definition: termiterator.h:158
Define XAPIAN_VISIBILITY_* macros.
TermIterator()
Default constructor.
Definition: termiterator.h:80
Class for iterating over term positions.
std::input_iterator_tag iterator_category
Definition: termiterator.h:150
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
Definition: types.h:79
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
Definition: query.h:670
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
std::string value_type
Definition: termiterator.h:152
Xapian::termcount_diff difference_type
Definition: termiterator.h:154
Class for wrapping type returned by an input_iterator.
#define XAPIAN_NOEXCEPT
Definition: attributes.h:39