[python3] Simplify generated wrapper post-processing
[xapian.git] / xapian-core / include / xapian / valueiterator.h
blob545c52847c67eea5f38766755c350d57fbdfda04
1 /** @file valueiterator.h
2 * @brief Class for iterating over document values.
3 */
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
19 * USA
22 #ifndef XAPIAN_INCLUDED_VALUEITERATOR_H
23 #define XAPIAN_INCLUDED_VALUEITERATOR_H
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error "Never use <xapian/valueiterator.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/types.h>
35 #include <xapian/visibility.h>
37 namespace Xapian {
39 /// Class for iterating over document values.
40 class XAPIAN_VISIBILITY_DEFAULT ValueIterator {
41 void decref();
43 public:
44 /// Class representing the ValueIterator internals.
45 class Internal;
46 /// @private @internal Reference counted internals.
47 Internal * internal;
49 /** @private @internal Wrap an existing Internal. */
50 XAPIAN_VISIBILITY_INTERNAL
51 explicit ValueIterator(Internal *internal_);
53 /// Copy constructor.
54 ValueIterator(const ValueIterator & o);
56 /// Assignment.
57 ValueIterator & operator=(const ValueIterator & o);
59 /** Default constructor.
61 * Creates an uninitialised iterator, which can't be used before being
62 * assigned to, but is sometimes syntactically convenient.
64 XAPIAN_NOTHROW(ValueIterator())
65 : internal(0) { }
67 /// Destructor.
68 ~ValueIterator() {
69 if (internal) decref();
72 /// Return the value at the current position.
73 std::string operator*() const;
75 /// Advance the iterator to the next position.
76 ValueIterator & operator++();
78 /// Advance the iterator to the next position (postfix version).
79 DerefWrapper_<std::string> operator++(int) {
80 const std::string & value(**this);
81 operator++();
82 return DerefWrapper_<std::string>(value);
85 /** Return the docid at the current position.
87 * If we're iterating over values of a document, this method will throw
88 * Xapian::InvalidOperationError.
90 Xapian::docid get_docid() const;
92 /** Return the value slot number for the current position.
94 * If the iterator is over all values in a slot, this returns that slot's
95 * number. If the iterator is over the values in a particular document,
96 * it returns the number of each slot in turn.
98 Xapian::valueno get_valueno() const;
100 /** Advance the iterator to document id or value slot @a docid_or_slot.
102 * If this iterator is over values in a document, then this method
103 * advances the iterator to value slot @a docid_or_slot, or the first slot
104 * after it if there is no value in slot @a slot.
106 * If this iterator is over values in a particular slot, then this
107 * method advances the iterator to document id @a docid_or_slot, or the
108 * first document id after it if there is no value in the slot we're
109 * iterating over for document @a docid_or_slot.
111 * Note: The "two-faced" nature of this method is due to how C++
112 * overloading works. Xapian::docid and Xapian::valueno are both typedefs
113 * for the same unsigned integer type, so overloading can't distinguish
114 * them.
116 * @param docid_or_slot The docid/slot to advance to.
118 void skip_to(Xapian::docid docid_or_slot);
120 /** Check if the specified docid occurs.
122 * The caller is required to ensure that the specified document id
123 * @a did actually exists in the database.
125 * This method acts like skip_to() if that can be done at little extra
126 * cost, in which case it then returns true. This is how
127 * glass databases behave because they store values in streams which allow
128 * for an efficient implementation of skip_to().
130 * Otherwise it simply checks if a particular docid is present. If it
131 * is, it returns true. If it isn't, it returns false, and leaves the
132 * position unspecified (and hence the result of calling methods which
133 * depend on the current position, such as get_docid(), are also
134 * unspecified). In this state, next() will advance to the first matching
135 * position after document @a did, and skip_to() will act as it would if
136 * the position was the first matching position after document @a did.
138 * Currently the inmemory and remote backends behave in the
139 * latter way because they don't support streamed values and so skip_to()
140 * must check each document it skips over which is significantly slower.
142 * @param docid The document id to check.
144 #ifndef check
145 bool check(Xapian::docid docid);
146 #else
147 // The AssertMacros.h header in the OS X SDK currently defines a check
148 // macro. Apple have deprecated check() in favour of __Check() and
149 // plan to remove check() in a "future release", but for now prevent
150 // expansion of check by adding parentheses in the method prototype:
151 // http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
153 // We do this conditionally, as these parentheses trip up SWIG's
154 // parser:
155 // https://github.com/swig/swig/issues/45
156 bool (check)(Xapian::docid docid);
157 #endif
159 /// Return a string describing this object.
160 std::string get_description() const;
162 /** @private @internal ValueIterator is what the C++ STL calls an
163 * input_iterator.
165 * The following typedefs allow std::iterator_traits<> to work so that
166 * this iterator can be used with the STL.
168 * These are deliberately hidden from the Doxygen-generated docs, as the
169 * machinery here isn't interesting to API users. They just need to know
170 * that Xapian iterator classes are compatible with the STL.
172 // @{
173 /// @private
174 typedef std::input_iterator_tag iterator_category;
175 /// @private
176 typedef std::string value_type;
177 /// @private
178 typedef Xapian::doccount_diff difference_type;
179 /// @private
180 typedef std::string * pointer;
181 /// @private
182 typedef std::string & reference;
183 // @}
186 bool
187 XAPIAN_NOTHROW(operator==(const ValueIterator &a, const ValueIterator &b));
189 /// Equality test for ValueIterator objects.
190 inline bool
191 operator==(const ValueIterator &a, const ValueIterator &b) XAPIAN_NOEXCEPT
193 // Use a pointer comparison - this ensures both that (a == a) and correct
194 // handling of end iterators (which we ensure have NULL internals).
195 return a.internal == b.internal;
198 bool
199 XAPIAN_NOTHROW(operator!=(const ValueIterator &a, const ValueIterator &b));
201 /// Inequality test for ValueIterator objects.
202 inline bool
203 operator!=(const ValueIterator &a, const ValueIterator &b) XAPIAN_NOEXCEPT
205 return !(a == b);
210 #endif // XAPIAN_INCLUDED_VALUEITERATOR_H