xapian-core  2.0.0
postingiterator.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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_POSTINGITERATOR_H
22 #define XAPIAN_INCLUDED_POSTINGITERATOR_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/postingiterator.h> directly; include <xapian.h> instead.
26 #endif
27 
28 #include <iterator>
29 #include <string>
30 
31 #include <xapian/attributes.h>
32 #include <xapian/derefwrapper.h>
34 #include <xapian/types.h>
35 #include <xapian/visibility.h>
36 
37 namespace Xapian {
38 
41  public:
43  class Internal;
45  Internal * internal;
46 
49  explicit PostingIterator(Internal *internal_);
50 
53 
55  PostingIterator & operator=(const PostingIterator & o);
56 
59  : internal(o.internal) {
60  o.internal = nullptr;
61  }
62 
65  if (this != &o) {
66  if (internal) decref();
67  internal = o.internal;
68  o.internal = nullptr;
69  }
70  return *this;
71  }
72 
78  PostingIterator() noexcept
79  : internal() { }
80 
83  if (internal) decref();
84  }
85 
87  Xapian::docid operator*() const;
88 
90  Xapian::termcount get_wdf() const;
91 
93  Xapian::termcount get_doclength() const;
94 
96  Xapian::termcount get_unique_terms() const;
97 
99  Xapian::termcount get_wdfdocmax() const;
100 
101 #if 0 // FIXME: TermIterator supports this, so PostingIterator really ought to.
103  Xapian::termcount positionlist_count() const;
104 #endif
105 
107  PositionIterator positionlist_begin() const;
108 
111  return PositionIterator();
112  }
113 
115  PostingIterator & operator++();
116 
119  Xapian::docid did(**this);
120  operator++();
121  return DerefWrapper_<Xapian::docid>(did);
122  }
123 
130  void skip_to(Xapian::docid did);
131 
133  std::string get_description() const;
134 
145  // @{
147  typedef std::input_iterator_tag iterator_category;
153  typedef value_type* pointer;
156  // @}
157 
158  private:
159  void decref();
160 
162  void post_advance(Internal * res);
163 };
164 
166 inline bool
167 operator==(const PostingIterator& a, const PostingIterator& b) noexcept
168 {
169  // Use a pointer comparison - this ensures both that (a == a) and correct
170  // handling of end iterators (which we ensure have NULL internals).
171  return a.internal == b.internal;
172 }
173 
175 inline bool
176 operator!=(const PostingIterator& a, const PostingIterator& b) noexcept
177 {
178  return !(a == b);
179 }
180 
181 }
182 
183 #endif // XAPIAN_INCLUDED_POSTINGITERATOR_H
Compiler attribute macros.
Class for iterating over term positions.
Class for iterating over a list of terms.
PositionIterator positionlist_end() const noexcept
Return an end PositionIterator for the current document.
std::input_iterator_tag iterator_category
~PostingIterator()
Destructor.
DerefWrapper_< Xapian::docid > operator++(int)
Advance the iterator to the next position (postfix version).
void post_advance(Internal *res)
Xapian::doccount_diff difference_type
PostingIterator(PostingIterator &&o)
Move constructor.
PostingIterator() noexcept
Default constructor.
PostingIterator & operator=(PostingIterator &&o)
Move assignment operator.
Class for wrapping type returned by an input_iterator.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
XAPIAN_DOCID_BASE_TYPE doccount_diff
A signed difference between two counts of documents.
Definition: types.h:44
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
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
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
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