xapian-core  1.4.19
termiterator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2009,2010,2011,2012,2013,2014,2015 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(0) { }
82 
85  if (internal) decref();
86  }
87 
89  std::string operator*() const;
90 
92  Xapian::termcount get_wdf() const;
93 
95  Xapian::doccount get_termfreq() const;
96 
98  Xapian::termcount positionlist_count() const;
99 
101  PositionIterator positionlist_begin() const;
102 
104  PositionIterator XAPIAN_NOTHROW(positionlist_end() const) {
105  return PositionIterator();
106  }
107 
109  TermIterator & operator++();
110 
113  const std::string & term(**this);
114  operator++();
115  return DerefWrapper_<std::string>(term);
116  }
117 
127  void skip_to(const std::string &term);
128 
130  std::string get_description() const;
131 
142  // @{
144  typedef std::input_iterator_tag iterator_category;
146  typedef std::string value_type;
150  typedef std::string * pointer;
152  typedef std::string & reference;
153  // @}
154 
155  private:
156  void decref();
157 
158  void post_advance(Internal * res);
159 };
160 
161 bool
162 XAPIAN_NOTHROW(operator==(const TermIterator &a, const TermIterator &b));
163 
165 inline bool
167 {
168  // Use a pointer comparison - this ensures both that (a == a) and correct
169  // handling of end iterators (which we ensure have NULL internals).
170  return a.internal == b.internal;
171 }
172 
173 bool
174 XAPIAN_NOTHROW(operator!=(const TermIterator &a, const TermIterator &b));
175 
177 inline bool
179 {
180  return !(a == b);
181 }
182 
183 }
184 
185 #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:112
typedefs for Xapian
std::string * pointer
Definition: termiterator.h:150
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:104
std::string & reference
Definition: termiterator.h:152
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:144
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:146
Xapian::termcount_diff difference_type
Definition: termiterator.h:148
Class for wrapping type returned by an input_iterator.
#define XAPIAN_NOEXCEPT
Definition: attributes.h:39