xapian-core  1.4.27
eset.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2015,2016 Olly Betts
5  *
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.
10  *
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.
15  *
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
20  */
21 
22 #ifndef XAPIAN_INCLUDED_ESET_H
23 #define XAPIAN_INCLUDED_ESET_H
24 
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
28 
29 #include <iterator>
30 #include <string>
31 
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>
37 
38 namespace Xapian {
39 
40 class ESetIterator;
41 
44  friend class ESetIterator;
45 
46  public:
48  class Internal;
51 
56  ESet(const ESet & o);
57 
62  ESet & operator=(const ESet & o);
63 
64 #ifdef XAPIAN_MOVE_SEMANTICS
65  ESet(ESet && o);
67 
69  ESet & operator=(ESet && o);
70 #endif
71 
76  ESet();
77 
79  ~ESet();
80 
82  Xapian::doccount size() const;
83 
85  bool empty() const { return size() == 0; }
86 
92  Xapian::termcount get_ebound() const;
93 
95  void swap(ESet & o) { internal.swap(o.internal); }
96 
98  ESetIterator begin() const;
99 
101  ESetIterator end() const;
102 
104  ESetIterator operator[](Xapian::doccount i) const;
105 
107  ESetIterator back() const;
108 
110  std::string get_description() const;
111 
123  // @{
135  typedef value_type * pointer;
137  typedef const value_type * const_pointer;
139  typedef value_type & reference;
141  typedef const value_type & const_reference;
142  // @}
143  //
153  // @{
154  // The size is fixed once created.
155  Xapian::doccount max_size() const { return size(); }
156  // @}
157 };
158 
161  friend class ESet;
162 
163  ESetIterator(const Xapian::ESet & eset_, Xapian::doccount off_from_end_)
164  : eset(eset_), off_from_end(off_from_end_) { }
165 
166  public:
169 
176 
178  ESetIterator() : off_from_end(0) { }
179 
181  std::string operator*() const;
182 
185  --off_from_end;
186  return *this;
187  }
188 
191  ESetIterator retval = *this;
192  --off_from_end;
193  return retval;
194  }
195 
198  ++off_from_end;
199  return *this;
200  }
201 
204  ESetIterator retval = *this;
205  ++off_from_end;
206  return retval;
207  }
208 
219  // @{
221  typedef std::random_access_iterator_tag iterator_category;
223  typedef std::string value_type;
227  typedef std::string * pointer;
229  typedef std::string & reference;
230  // @}
231 
233  ESetIterator & operator+=(difference_type n) {
234  off_from_end -= n;
235  return *this;
236  }
237 
239  ESetIterator & operator-=(difference_type n) {
240  off_from_end += n;
241  return *this;
242  }
243 
248  ESetIterator operator+(difference_type n) const {
249  return ESetIterator(eset, off_from_end - n);
250  }
251 
256  ESetIterator operator-(difference_type n) const {
257  return ESetIterator(eset, off_from_end + n);
258  }
259 
261  difference_type operator-(const ESetIterator& o) const {
262  return difference_type(o.off_from_end) - difference_type(off_from_end);
263  }
264 
266  double get_weight() const;
267 
269  std::string get_description() const;
270 };
271 
272 bool
273 XAPIAN_NOTHROW(operator==(const ESetIterator &a, const ESetIterator &b));
274 
276 inline bool
278 {
279  return a.off_from_end == b.off_from_end;
280 }
281 
282 inline bool
283 XAPIAN_NOTHROW(operator!=(const ESetIterator &a, const ESetIterator &b));
284 
286 inline bool
288 {
289  return !(a == b);
290 }
291 
292 bool
293 XAPIAN_NOTHROW(operator<(const ESetIterator &a, const ESetIterator &b));
294 
296 inline bool
298 {
299  return a.off_from_end > b.off_from_end;
300 }
301 
302 inline bool
303 XAPIAN_NOTHROW(operator>(const ESetIterator &a, const ESetIterator &b));
304 
306 inline bool
308 {
309  return b < a;
310 }
311 
312 inline bool
313 XAPIAN_NOTHROW(operator>=(const ESetIterator &a, const ESetIterator &b));
314 
316 inline bool
318 {
319  return !(a < b);
320 }
321 
322 inline bool
323 XAPIAN_NOTHROW(operator<=(const ESetIterator &a, const ESetIterator &b));
324 
326 inline bool
328 {
329  return !(b < a);
330 }
331 
336 inline ESetIterator
338 {
339  return it + n;
340 }
341 
342 // Inlined methods of ESet which need ESetIterator to have been defined:
343 
344 inline ESetIterator
345 ESet::begin() const {
346  return ESetIterator(*this, size());
347 }
348 
349 inline ESetIterator
350 ESet::end() const {
351  // Decrementing the result of end() needs to work, so we must pass in
352  // *this here.
353  return ESetIterator(*this, 0);
354 }
355 
356 inline ESetIterator
358  return ESetIterator(*this, size() - i);
359 }
360 
361 inline ESetIterator
362 ESet::back() const {
363  return ESetIterator(*this, 1);
364 }
365 
366 }
367 
368 #endif // XAPIAN_INCLUDED_ESET_H
difference_type operator-(const ESetIterator &o) const
Return the number of positions between o and this iterator.
Definition: eset.h:261
std::random_access_iterator_tag iterator_category
Definition: eset.h:221
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
bool operator>=(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:317
typedefs for Xapian
Xapian::ESetIterator value_type
Definition: eset.h:125
Xapian::termcount_diff difference_type
Definition: eset.h:225
ESetIterator back() const
Return iterator pointing to the last object in this ESet.
Definition: eset.h:362
void swap(ESet &o)
Efficiently swap this ESet object with another.
Definition: eset.h:95
Class which actually implements Xapian::ESet.
Definition: esetinternal.h:77
ESetIterator operator--(int)
Move the iterator to the previous position (postfix version).
Definition: eset.h:203
Compiler attribute macros.
bool operator!=(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:287
bool operator==(const ESetIterator &a, const ESetIterator &b)
Equality test for ESetIterator objects.
Definition: eset.h:277
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
std::string * pointer
Definition: eset.h:227
bool operator<(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:297
ESetIterator & operator--()
Move the iterator to the previous position.
Definition: eset.h:197
ESetIterator & operator+=(difference_type n)
Move the iterator forwards by n positions.
Definition: eset.h:233
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
ESetIterator begin() const
Return iterator pointing to the first item in this ESet.
Definition: eset.h:345
ESetIterator operator++(int)
Advance the iterator to the next position (postfix version).
Definition: eset.h:190
ESetIterator operator-(difference_type n) const
Return the iterator decremented by n positions.
Definition: eset.h:256
bool operator<=(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:327
Define XAPIAN_VISIBILITY_* macros.
ESetIterator operator+(difference_type n) const
Return the iterator incremented by n positions.
Definition: eset.h:248
value_type * pointer
Definition: eset.h:135
std::string value_type
Definition: eset.h:223
ESetIterator()
Create an unpositioned ESetIterator.
Definition: eset.h:178
bool operator>(const ESetIterator &a, const ESetIterator &b)
Inequality test for ESetIterator objects.
Definition: eset.h:307
Xapian::ESet eset
Definition: eset.h:168
Xapian::ESetIterator const_iterator
Definition: eset.h:133
ESetIterator operator[](Xapian::doccount i) const
Return iterator pointing to the i-th object in this ESet.
Definition: eset.h:357
Iterator over a Xapian::ESet.
Definition: eset.h:160
Xapian::Internal::intrusive_ptr< Internal > internal
Definition: eset.h:48
Xapian::doccount max_size() const
Definition: eset.h:155
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
Definition: types.h:79
Xapian::termcount size_type
Definition: eset.h:127
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
Definition: query.h:670
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
ESetIterator operator+(ESetIterator::difference_type n, const ESetIterator &it)
Return ESetIterator it incremented by n positions.
Definition: eset.h:337
Xapian::ESet::size_type off_from_end
Definition: eset.h:175
ESetIterator(const Xapian::ESet &eset_, Xapian::doccount off_from_end_)
Definition: eset.h:163
Xapian::termcount_diff difference_type
Definition: eset.h:129
const value_type * const_pointer
Definition: eset.h:137
Class representing a list of search results.
Definition: eset.h:43
std::string & reference
Definition: eset.h:229
ESetIterator & operator++()
Advance the iterator to the next position.
Definition: eset.h:184
const value_type & const_reference
Definition: eset.h:141
bool empty() const
Return true if this ESet object is empty.
Definition: eset.h:85
ESetIterator & operator-=(difference_type n)
Move the iterator back by n positions.
Definition: eset.h:239
value_type & reference
Definition: eset.h:139
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:81
stemming algorithms
#define XAPIAN_NOEXCEPT
Definition: attributes.h:39
ESetIterator end() const
Return iterator pointing to just after the last item in this ESet.
Definition: eset.h:350
Xapian::ESetIterator iterator
Definition: eset.h:131