2 * @brief Class for iterating over term positions.
4 /* Copyright (C) 2008,2009,2010,2011,2012,2013,2014,2015 Olly Betts
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.
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.
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
22 #ifndef XAPIAN_INCLUDED_POSITIONITERATOR_H
23 #define XAPIAN_INCLUDED_POSITIONITERATOR_H
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/positioniterator.h> directly; include <xapian.h> instead.
32 #include <xapian/attributes.h>
33 #include <xapian/derefwrapper.h>
34 #include <xapian/types.h>
35 #include <xapian/visibility.h>
39 /// Class for iterating over term positions.
40 class XAPIAN_VISIBILITY_DEFAULT PositionIterator
{
44 /// Class representing the PositionIterator internals.
46 /// @private @internal Reference counted internals.
49 /// @private @internal Construct given internals.
50 explicit PositionIterator(Internal
*internal_
);
53 PositionIterator(const PositionIterator
& o
);
56 PositionIterator
& operator=(const PositionIterator
& o
);
58 #ifdef XAPIAN_MOVE_SEMANTICS
60 PositionIterator(PositionIterator
&& o
)
61 : internal(o
.internal
) {
65 /// Move assignment operator.
66 PositionIterator
& operator=(PositionIterator
&& o
) {
68 if (internal
) decref();
69 internal
= o
.internal
;
76 /** Default constructor.
78 * Creates an uninitialised iterator, which can't be used before being
79 * assigned to, but is sometimes syntactically convenient.
81 XAPIAN_NOTHROW(PositionIterator())
86 if (internal
) decref();
89 /// Return the term position at the current iterator position.
90 Xapian::termpos
operator*() const;
92 /// Advance the iterator to the next position.
93 PositionIterator
& operator++();
95 /// Advance the iterator to the next position (postfix version).
96 DerefWrapper_
<Xapian::termpos
> operator++(int) {
97 Xapian::termpos
pos(**this);
99 return DerefWrapper_
<Xapian::termpos
>(pos
);
102 /** Advance the iterator to term position @a termpos.
104 * @param termpos The position to advance to. If this position isn't in
105 * the stream being iterated, then the iterator is moved
106 * to the next term position after it which is.
108 void skip_to(Xapian::termpos termpos
);
110 /// Return a string describing this object.
111 std::string
get_description() const;
113 /** @private @internal PositionIterator is what the C++ STL calls an
116 * The following typedefs allow std::iterator_traits<> to work so that
117 * this iterator can be used with the STL.
119 * These are deliberately hidden from the Doxygen-generated docs, as the
120 * machinery here isn't interesting to API users. They just need to know
121 * that Xapian iterator classes are compatible with the STL.
125 typedef std::input_iterator_tag iterator_category
;
127 typedef Xapian::termpos value_type
;
129 typedef Xapian::termpos_diff difference_type
;
131 typedef Xapian::termpos
* pointer
;
133 typedef Xapian::termpos
& reference
;
138 XAPIAN_NOTHROW(operator==(const PositionIterator
&a
, const PositionIterator
&b
));
140 /// Equality test for PositionIterator objects.
142 operator==(const PositionIterator
&a
, const PositionIterator
&b
) XAPIAN_NOEXCEPT
144 // Use a pointer comparison - this ensures both that (a == a) and correct
145 // handling of end iterators (which we ensure have NULL internals).
146 return a
.internal
== b
.internal
;
150 XAPIAN_NOTHROW(operator!=(const PositionIterator
&a
, const PositionIterator
&b
));
152 /// Inequality test for PositionIterator objects.
154 operator!=(const PositionIterator
&a
, const PositionIterator
&b
) XAPIAN_NOEXCEPT
161 #endif // XAPIAN_INCLUDED_POSITIONITERATOR_H