generate-exceptions,include/xapian/: Remove XAPIAN_PURE_FUNCTION
[xapian.git] / xapian-core / include / xapian / termiterator.h
blobf4e5c504f81d1365dcf30053593610390f60850f
1 /** @file termiterator.h
2 * @brief Class for iterating over a list of terms
3 */
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
19 * USA
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."
27 #endif
29 #include <iterator>
30 #include <string>
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>
38 namespace Xapian {
40 /// Class for iterating over a list of terms.
41 class XAPIAN_VISIBILITY_DEFAULT TermIterator {
42 public:
43 /// Class representing the TermIterator internals.
44 class Internal;
45 /// @private @internal Reference counted internals.
46 Internal * internal;
48 /// @private @internal Construct given internals.
49 explicit TermIterator(Internal *internal_);
51 /// Copy constructor.
52 TermIterator(const TermIterator & o);
54 /// Assignment.
55 TermIterator & operator=(const TermIterator & o);
57 /** Default constructor.
59 * Creates an uninitialised iterator, which can't be used before being
60 * assigned to, but is sometimes syntactically convenient.
62 XAPIAN_NOTHROW(TermIterator())
63 : internal(0) { }
65 /// Destructor.
66 ~TermIterator() {
67 if (internal) decref();
70 /// Return the term at the current position.
71 std::string operator*() const;
73 /// Return the wdf for the term at the current position.
74 Xapian::termcount get_wdf() const;
76 /// Return the term frequency for the term at the current position.
77 Xapian::doccount get_termfreq() const;
79 /// Return the length of the position list for the current position.
80 Xapian::termcount positionlist_count() const;
82 /// Return a PositionIterator for the current term.
83 PositionIterator positionlist_begin() const;
85 /// Return an end PositionIterator for the current term.
86 PositionIterator XAPIAN_NOTHROW(positionlist_end() const) {
87 return PositionIterator();
90 /// Advance the iterator to the next position.
91 TermIterator & operator++();
93 /// Advance the iterator to the next position (postfix version).
94 DerefWrapper_<std::string> operator++(int) {
95 const std::string & term(**this);
96 operator++();
97 return DerefWrapper_<std::string>(term);
100 /** Advance the iterator to term @a term.
102 * If the iteration is over an unsorted list of terms, then this method
103 * will throw Xapian::InvalidOperationError.
105 * @param term The term to advance to. If this term isn't in
106 * the stream being iterated, then the iterator is moved
107 * to the next term after it which is.
109 void skip_to(const std::string &term);
111 /// Return a string describing this object.
112 std::string get_description() const;
114 /** @private @internal TermIterator is what the C++ STL calls an
115 * input_iterator.
117 * The following typedefs allow std::iterator_traits<> to work so that
118 * this iterator can be used with the STL.
120 * These are deliberately hidden from the Doxygen-generated docs, as the
121 * machinery here isn't interesting to API users. They just need to know
122 * that Xapian iterator classes are compatible with the STL.
124 // @{
125 /// @private
126 typedef std::input_iterator_tag iterator_category;
127 /// @private
128 typedef std::string value_type;
129 /// @private
130 typedef Xapian::termcount_diff difference_type;
131 /// @private
132 typedef std::string * pointer;
133 /// @private
134 typedef std::string & reference;
135 // @}
137 private:
138 void decref();
140 void post_advance(Internal * res);
143 bool
144 XAPIAN_NOTHROW(operator==(const TermIterator &a, const TermIterator &b));
146 /// Equality test for TermIterator objects.
147 inline bool
148 operator==(const TermIterator &a, const TermIterator &b) XAPIAN_NOEXCEPT
150 // Use a pointer comparison - this ensures both that (a == a) and correct
151 // handling of end iterators (which we ensure have NULL internals).
152 return a.internal == b.internal;
155 bool
156 XAPIAN_NOTHROW(operator!=(const TermIterator &a, const TermIterator &b));
158 /// Inequality test for TermIterator objects.
159 inline bool
160 operator!=(const TermIterator &a, const TermIterator &b) XAPIAN_NOEXCEPT
162 return !(a == b);
167 #endif // XAPIAN_INCLUDED_TERMITERATOR_H