xapian-core  2.0.0
positioniterator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 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_POSITIONITERATOR_H
22 #define XAPIAN_INCLUDED_POSITIONITERATOR_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/positioniterator.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>
33 #include <xapian/types.h>
34 #include <xapian/visibility.h>
35 
36 namespace Xapian {
37 
40  void decref();
41 
42  public:
44  class Internal;
46  Internal * internal;
47 
50  explicit PositionIterator(Internal *internal_);
51 
54 
56  PositionIterator & operator=(const PositionIterator & 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  PositionIterator() noexcept
80  : internal() { }
81 
84  if (internal) decref();
85  }
86 
88  Xapian::termpos operator*() const;
89 
91  PositionIterator & operator++();
92 
95  Xapian::termpos pos(**this);
96  operator++();
98  }
99 
106  void skip_to(Xapian::termpos termpos);
107 
109  std::string get_description() const;
110 
121  // @{
123  typedef std::input_iterator_tag iterator_category;
129  typedef value_type* pointer;
132  // @}
133 };
134 
136 inline bool
137 operator==(const PositionIterator& a, const PositionIterator& b) noexcept
138 {
139  // Use a pointer comparison - this ensures both that (a == a) and correct
140  // handling of end iterators (which we ensure have NULL internals).
141  return a.internal == b.internal;
142 }
143 
145 inline bool
146 operator!=(const PositionIterator& a, const PositionIterator& b) noexcept
147 {
148  return !(a == b);
149 }
150 
151 }
152 
153 #endif // XAPIAN_INCLUDED_POSITIONITERATOR_H
Compiler attribute macros.
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:32
Class for iterating over term positions.
DerefWrapper_< Xapian::termpos > operator++(int)
Advance the iterator to the next position (postfix version).
PositionIterator() noexcept
Default constructor.
Xapian::termpos_diff difference_type
PositionIterator(PositionIterator &&o)
Move constructor.
PositionIterator & operator=(PositionIterator &&o)
Move assignment operator.
std::input_iterator_tag iterator_category
Xapian::termpos pos
Class for wrapping type returned by an input_iterator.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
XAPIAN_TERMPOS_BASE_TYPE termpos_diff
A signed difference between two term positions.
Definition: types.h:82
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_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:75
typedefs for Xapian
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29