[python3] Simplify generated wrapper post-processing
[xapian.git] / xapian-core / include / xapian / eset.h
blobd5d62540a5dad73c59cdd507e6b19e23c2d0bbe5
1 /** @file eset.h
2 * @brief Class representing a list of query expansion terms
3 */
4 /* Copyright (C) 2015,2016,2017 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_ESET_H
23 #define XAPIAN_INCLUDED_ESET_H
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error "Never use <xapian/eset.h> directly; include <xapian.h> instead."
27 #endif
29 #include <iterator>
30 #include <string>
32 #include <xapian/attributes.h>
33 #include <xapian/intrusive_ptr.h>
34 #include <xapian/stem.h>
35 #include <xapian/types.h>
36 #include <xapian/visibility.h>
38 namespace Xapian {
40 class ESetIterator;
42 /// Class representing a list of search results.
43 class XAPIAN_VISIBILITY_DEFAULT ESet {
44 friend class ESetIterator;
46 public:
47 /// Class representing the ESet internals.
48 class Internal;
49 /// @private @internal Reference counted internals.
50 Xapian::Internal::intrusive_ptr_nonnull<Internal> internal;
52 /** Copying is allowed.
54 * The internals are reference counted, so copying is cheap.
56 ESet(const ESet & o);
58 /** Copying is allowed.
60 * The internals are reference counted, so assignment is cheap.
62 ESet & operator=(const ESet & o);
64 /** Default constructor.
66 * Creates an empty ESet, mostly useful as a placeholder.
68 ESet();
70 /// Destructor.
71 ~ESet();
73 /** Return number of items in this ESet object. */
74 Xapian::doccount size() const;
76 /** Return true if this ESet object is empty. */
77 bool empty() const { return size() == 0; }
79 /** Return a bound on the full size of this ESet object.
81 * This is a bound on size() if get_eset() had been called with
82 * maxitems set high enough that all results were returned.
84 Xapian::termcount get_ebound() const;
86 /** Efficiently swap this ESet object with another. */
87 void swap(ESet & o) { internal.swap(o.internal); }
89 /** Return iterator pointing to the first item in this ESet. */
90 ESetIterator begin() const;
92 /** Return iterator pointing to just after the last item in this ESet. */
93 ESetIterator end() const;
95 /** Return iterator pointing to the i-th object in this ESet. */
96 ESetIterator operator[](Xapian::doccount i) const;
98 /** Return iterator pointing to the last object in this ESet. */
99 ESetIterator back() const;
101 /// Return a string describing this object.
102 std::string get_description() const;
104 /** @private @internal ESet is what the C++ STL calls a container.
106 * The following typedefs allow the class to be used in templates in the
107 * same way the standard containers can be.
109 * These are deliberately hidden from the Doxygen-generated docs, as the
110 * machinery here isn't interesting to API users. They just need to know
111 * that Xapian container classes are compatible with the STL.
113 * See "The C++ Programming Language", 3rd ed. section 16.3.1:
115 // @{
116 /// @private
117 typedef Xapian::ESetIterator value_type;
118 /// @private
119 typedef Xapian::termcount size_type;
120 /// @private
121 typedef Xapian::termcount_diff difference_type;
122 /// @private
123 typedef Xapian::ESetIterator iterator;
124 /// @private
125 typedef Xapian::ESetIterator const_iterator;
126 /// @private
127 typedef value_type * pointer;
128 /// @private
129 typedef const value_type * const_pointer;
130 /// @private
131 typedef value_type & reference;
132 /// @private
133 typedef const value_type & const_reference;
134 // @}
136 /** @private @internal ESet is what the C++ STL calls a container.
138 * The following methods allow the class to be used in templates in the
139 * same way the standard containers can be.
141 * These are deliberately hidden from the Doxygen-generated docs, as the
142 * machinery here isn't interesting to API users. They just need to know
143 * that Xapian container classes are compatible with the STL.
145 // @{
146 // The size is fixed once created.
147 Xapian::doccount max_size() const { return size(); }
148 // @}
151 /// Iterator over a Xapian::ESet.
152 class XAPIAN_VISIBILITY_DEFAULT ESetIterator {
153 friend class ESet;
155 ESetIterator(const Xapian::ESet & eset_, Xapian::doccount off_from_end_)
156 : eset(eset_), off_from_end(off_from_end_) { }
158 public:
159 /** @private @internal The ESet we are iterating over. */
160 Xapian::ESet eset;
162 /** @private @internal The current position of the iterator.
164 * We store the offset from the end of @a eset, since that means
165 * ESet::end() just needs to set this member to 0.
167 Xapian::ESet::size_type off_from_end;
169 /** Create an unpositioned ESetIterator. */
170 ESetIterator() : off_from_end(0) { }
172 /** Get the term at the current position. */
173 std::string operator*() const;
175 /// Advance the iterator to the next position.
176 ESetIterator & operator++() {
177 --off_from_end;
178 return *this;
181 /// Advance the iterator to the next position (postfix version).
182 ESetIterator operator++(int) {
183 ESetIterator retval = *this;
184 --off_from_end;
185 return retval;
188 /// Move the iterator to the previous position.
189 ESetIterator & operator--() {
190 ++off_from_end;
191 return *this;
194 /// Move the iterator to the previous position (postfix version).
195 ESetIterator operator--(int) {
196 ESetIterator retval = *this;
197 ++off_from_end;
198 return retval;
201 /** @private @internal ESetIterator is what the C++ STL calls an
202 * random_access_iterator.
204 * The following typedefs allow std::iterator_traits<> to work so that
205 * this iterator can be used with the STL.
207 * These are deliberately hidden from the Doxygen-generated docs, as the
208 * machinery here isn't interesting to API users. They just need to know
209 * that Xapian iterator classes are compatible with the STL.
211 // @{
212 /// @private
213 typedef std::random_access_iterator_tag iterator_category;
214 /// @private
215 typedef std::string value_type;
216 /// @private
217 typedef Xapian::termcount_diff difference_type;
218 /// @private
219 typedef std::string * pointer;
220 /// @private
221 typedef std::string & reference;
222 // @}
224 /// Move the iterator forwards by n positions.
225 ESetIterator & operator+=(difference_type n) {
226 off_from_end -= n;
227 return *this;
230 /// Move the iterator back by n positions.
231 ESetIterator & operator-=(difference_type n) {
232 off_from_end += n;
233 return *this;
236 /** Return the iterator incremented by @a n positions.
238 * If @a n is negative, decrements by (-n) positions.
240 ESetIterator operator+(difference_type n) const {
241 return ESetIterator(eset, off_from_end - n);
244 /** Return the iterator decremented by @a n positions.
246 * If @a n is negative, increments by (-n) positions.
248 ESetIterator operator-(difference_type n) const {
249 return ESetIterator(eset, off_from_end + n);
252 /** Return the number of positions between @a o and this iterator. */
253 difference_type operator-(const ESetIterator& o) const {
254 return difference_type(o.off_from_end) - difference_type(off_from_end);
257 /** Get the weight for the current position. */
258 double get_weight() const;
260 /// Return a string describing this object.
261 std::string get_description() const;
264 bool
265 XAPIAN_NOTHROW(operator==(const ESetIterator &a, const ESetIterator &b));
267 /// Equality test for ESetIterator objects.
268 inline bool
269 operator==(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
271 return a.off_from_end == b.off_from_end;
274 inline bool
275 XAPIAN_NOTHROW(operator!=(const ESetIterator &a, const ESetIterator &b));
277 /// Inequality test for ESetIterator objects.
278 inline bool
279 operator!=(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
281 return !(a == b);
284 bool
285 XAPIAN_NOTHROW(operator<(const ESetIterator &a, const ESetIterator &b));
287 /// Inequality test for ESetIterator objects.
288 inline bool
289 operator<(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
291 return a.off_from_end > b.off_from_end;
294 inline bool
295 XAPIAN_NOTHROW(operator>(const ESetIterator &a, const ESetIterator &b));
297 /// Inequality test for ESetIterator objects.
298 inline bool
299 operator>(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
301 return b < a;
304 inline bool
305 XAPIAN_NOTHROW(operator>=(const ESetIterator &a, const ESetIterator &b));
307 /// Inequality test for ESetIterator objects.
308 inline bool
309 operator>=(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
311 return !(a < b);
314 inline bool
315 XAPIAN_NOTHROW(operator<=(const ESetIterator &a, const ESetIterator &b));
317 /// Inequality test for ESetIterator objects.
318 inline bool
319 operator<=(const ESetIterator &a, const ESetIterator &b) XAPIAN_NOEXCEPT
321 return !(b < a);
324 /** Return ESetIterator @a it incremented by @a n positions.
326 * If @a n is negative, decrements by (-n) positions.
328 inline ESetIterator
329 operator+(ESetIterator::difference_type n, const ESetIterator& it)
331 return it + n;
334 // Inlined methods of ESet which need ESetIterator to have been defined:
336 inline ESetIterator
337 ESet::begin() const {
338 return ESetIterator(*this, size());
341 inline ESetIterator
342 ESet::end() const {
343 // Decrementing the result of end() needs to work, so we must pass in
344 // *this here.
345 return ESetIterator(*this, 0);
348 inline ESetIterator
349 ESet::operator[](Xapian::doccount i) const {
350 return ESetIterator(*this, size() - i);
353 inline ESetIterator
354 ESet::back() const {
355 return ESetIterator(*this, 1);
360 #endif // XAPIAN_INCLUDED_ESET_H