xapian-core  2.0.0
termiterator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007-2024 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_TERMITERATOR_H
22 #define XAPIAN_INCLUDED_TERMITERATOR_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/termiterator.h> directly; include <xapian.h> instead.
26 #endif
27 
28 #include <iterator>
29 #include <string>
30 #include <string_view>
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 
50  explicit TermIterator(Internal *internal_);
51 
53  TermIterator(const TermIterator & o);
54 
56  TermIterator & operator=(const TermIterator & o);
57 
60  : internal(o.internal) {
61  o.internal = nullptr;
62  }
63 
66  if (this != &o) {
67  if (internal) decref();
68  internal = o.internal;
69  o.internal = nullptr;
70  }
71  return *this;
72  }
73 
79  TermIterator() noexcept
80  : internal() { }
81 
84  if (internal) decref();
85  }
86 
88  std::string operator*() const;
89 
91  Xapian::termcount get_wdf() const;
92 
100  Xapian::doccount get_termfreq() const;
101 
103  Xapian::termcount positionlist_count() const;
104 
106  PositionIterator positionlist_begin() const;
107 
110  return PositionIterator();
111  }
112 
114  TermIterator & operator++();
115 
118  const std::string & term(**this);
119  operator++();
121  }
122 
132  void skip_to(std::string_view term);
133 
135  std::string get_description() const;
136 
147  // @{
149  typedef std::input_iterator_tag iterator_category;
151  typedef std::string value_type;
155  typedef value_type* pointer;
158  // @}
159 
160  private:
161  void decref();
162 
164  void post_advance(Internal * res);
165 };
166 
168 inline bool
169 operator==(const TermIterator& a, const TermIterator& b) noexcept
170 {
171  // Use a pointer comparison - this ensures both that (a == a) and correct
172  // handling of end iterators (which we ensure have NULL internals).
173  return a.internal == b.internal;
174 }
175 
177 inline bool
178 operator!=(const TermIterator& a, const TermIterator& b) noexcept
179 {
180  return !(a == b);
181 }
182 
183 }
184 
185 #endif // XAPIAN_INCLUDED_TERMITERATOR_H
Compiler attribute macros.
Class for iterating over term positions.
Abstract base class for termlists.
Definition: termlist.h:42
Class for iterating over a list of terms.
Definition: termiterator.h:41
TermIterator(TermIterator &&o)
Move constructor.
Definition: termiterator.h:59
std::string value_type
Definition: termiterator.h:151
PositionIterator positionlist_end() const noexcept
Return an end PositionIterator for the current term.
Definition: termiterator.h:109
DerefWrapper_< std::string > operator++(int)
Advance the iterator to the next position (postfix version).
Definition: termiterator.h:117
Xapian::termcount_diff difference_type
Definition: termiterator.h:153
value_type * pointer
Definition: termiterator.h:155
TermIterator & operator=(TermIterator &&o)
Move assignment operator.
Definition: termiterator.h:65
~TermIterator()
Destructor.
Definition: termiterator.h:83
TermIterator() noexcept
Default constructor.
Definition: termiterator.h:79
std::input_iterator_tag iterator_category
Definition: termiterator.h:149
string term
Class for wrapping type returned by an input_iterator.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
Definition: types.h:71
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
bool operator==(const ESetIterator &a, const ESetIterator &b) noexcept
Equality test for ESetIterator objects.
Definition: eset.h:271
bool operator!=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:278
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
Definition: query.h:827
Class for iterating over term positions.
typedefs for Xapian
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29