2 * @brief Class for iterating over a list of terms
4 /* Copyright (C) 2007,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_TERMITERATOR_H
23 #define XAPIAN_INCLUDED_TERMITERATOR_H
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/termiterator.h> directly; include <xapian.h> instead.
32 #include <xapian/attributes.h>
33 #include <xapian/derefwrapper.h>
34 #include <xapian/positioniterator.h>
35 #include <xapian/types.h>
36 #include <xapian/visibility.h>
40 /// Class for iterating over a list of terms.
41 class XAPIAN_VISIBILITY_DEFAULT TermIterator
{
43 /// Class representing the TermIterator internals.
45 /// @private @internal Reference counted internals.
48 /// @private @internal Construct given internals.
49 explicit TermIterator(Internal
*internal_
);
52 TermIterator(const TermIterator
& o
);
55 TermIterator
& operator=(const TermIterator
& o
);
57 #ifdef XAPIAN_MOVE_SEMANTICS
59 TermIterator(TermIterator
&& o
)
60 : internal(o
.internal
) {
64 /// Move assignment operator.
65 TermIterator
& operator=(TermIterator
&& o
) {
67 if (internal
) decref();
68 internal
= o
.internal
;
75 /** Default constructor.
77 * Creates an uninitialised iterator, which can't be used before being
78 * assigned to, but is sometimes syntactically convenient.
80 XAPIAN_NOTHROW(TermIterator())
85 if (internal
) decref();
88 /// Return the term at the current position.
89 std::string
operator*() const;
91 /// Return the wdf for the term at the current position.
92 Xapian::termcount
get_wdf() const;
94 /// Return the term frequency for the term at the current position.
95 Xapian::doccount
get_termfreq() const;
97 /// Return the length of the position list for the current position.
98 Xapian::termcount
positionlist_count() const;
100 /// Return a PositionIterator for the current term.
101 PositionIterator
positionlist_begin() const;
103 /// Return an end PositionIterator for the current term.
104 PositionIterator
XAPIAN_NOTHROW(positionlist_end() const) {
105 return PositionIterator();
108 /// Advance the iterator to the next position.
109 TermIterator
& operator++();
111 /// Advance the iterator to the next position (postfix version).
112 DerefWrapper_
<std::string
> operator++(int) {
113 const std::string
& term(**this);
115 return DerefWrapper_
<std::string
>(term
);
118 /** Advance the iterator to term @a term.
120 * If the iteration is over an unsorted list of terms, then this method
121 * will throw Xapian::InvalidOperationError.
123 * @param term The term to advance to. If this term isn't in
124 * the stream being iterated, then the iterator is moved
125 * to the next term after it which is.
127 void skip_to(const std::string
&term
);
129 /// Return a string describing this object.
130 std::string
get_description() const;
132 /** @private @internal TermIterator is what the C++ STL calls an
135 * The following typedefs allow std::iterator_traits<> to work so that
136 * this iterator can be used with the STL.
138 * These are deliberately hidden from the Doxygen-generated docs, as the
139 * machinery here isn't interesting to API users. They just need to know
140 * that Xapian iterator classes are compatible with the STL.
144 typedef std::input_iterator_tag iterator_category
;
146 typedef std::string value_type
;
148 typedef Xapian::termcount_diff difference_type
;
150 typedef std::string
* pointer
;
152 typedef std::string
& reference
;
158 void post_advance(Internal
* res
);
162 XAPIAN_NOTHROW(operator==(const TermIterator
&a
, const TermIterator
&b
));
164 /// Equality test for TermIterator objects.
166 operator==(const TermIterator
&a
, const TermIterator
&b
) XAPIAN_NOEXCEPT
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
;
174 XAPIAN_NOTHROW(operator!=(const TermIterator
&a
, const TermIterator
&b
));
176 /// Inequality test for TermIterator objects.
178 operator!=(const TermIterator
&a
, const TermIterator
&b
) XAPIAN_NOEXCEPT
185 #endif // XAPIAN_INCLUDED_TERMITERATOR_H