xapian-core  2.0.0
eset.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2015,2016,2017 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, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_ESET_H
22 #define XAPIAN_INCLUDED_ESET_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/eset.h> directly; include <xapian.h> instead.
26 #endif
27 
28 #include <iterator>
29 #include <string>
30 
31 #include <xapian/attributes.h>
32 #include <xapian/intrusive_ptr.h>
33 #include <xapian/stem.h>
34 #include <xapian/types.h>
35 #include <xapian/visibility.h>
36 
37 namespace Xapian {
38 
39 class ESetIterator;
40 
43  friend class ESetIterator;
44 
45  public:
47  class Internal;
50 
55  ESet(const ESet & o);
56 
61  ESet & operator=(const ESet & o);
62 
64  ESet(ESet && o);
65 
67  ESet & operator=(ESet && o);
68 
73  ESet();
74 
76  ~ESet();
77 
79  Xapian::termcount size() const;
80 
82  bool empty() const { return size() == 0; }
83 
89  Xapian::termcount get_ebound() const;
90 
92  void swap(ESet & o) { internal.swap(o.internal); }
93 
95  ESetIterator begin() const;
96 
98  ESetIterator end() const;
99 
101  ESetIterator operator[](Xapian::termcount i) const;
102 
104  ESetIterator back() const;
105 
107  std::string get_description() const;
108 
120  // @{
132  typedef value_type * pointer;
134  typedef const value_type * const_pointer;
139  // @}
140  //
150  // @{
151  // The size is fixed once created.
152  Xapian::termcount max_size() const { return size(); }
153  // @}
154 };
155 
158  friend class ESet;
159 
160  ESetIterator(const Xapian::ESet & eset_, Xapian::termcount off_from_end_)
161  : eset(eset_), off_from_end(off_from_end_) { }
162 
163  public:
166 
173 
175  ESetIterator() : off_from_end(0) { }
176 
178  std::string operator*() const;
179 
182  --off_from_end;
183  return *this;
184  }
185 
188  ESetIterator retval = *this;
189  --off_from_end;
190  return retval;
191  }
192 
195  ++off_from_end;
196  return *this;
197  }
198 
201  ESetIterator retval = *this;
202  ++off_from_end;
203  return retval;
204  }
205 
216  // @{
218  typedef std::random_access_iterator_tag iterator_category;
220  typedef std::string value_type;
224  typedef value_type* pointer;
227  // @}
228 
231  off_from_end -= n;
232  return *this;
233  }
234 
237  off_from_end += n;
238  return *this;
239  }
240 
246  return ESetIterator(eset, off_from_end - n);
247  }
248 
254  return ESetIterator(eset, off_from_end + n);
255  }
256 
259  return difference_type(o.off_from_end) - difference_type(off_from_end);
260  }
261 
263  double get_weight() const;
264 
266  std::string get_description() const;
267 };
268 
270 inline bool
271 operator==(const ESetIterator& a, const ESetIterator& b) noexcept
272 {
273  return a.off_from_end == b.off_from_end;
274 }
275 
277 inline bool
278 operator!=(const ESetIterator& a, const ESetIterator& b) noexcept
279 {
280  return !(a == b);
281 }
282 
284 inline bool
285 operator<(const ESetIterator& a, const ESetIterator& b) noexcept
286 {
287  return a.off_from_end > b.off_from_end;
288 }
289 
291 inline bool
292 operator>(const ESetIterator& a, const ESetIterator& b) noexcept
293 {
294  return b < a;
295 }
296 
298 inline bool
299 operator>=(const ESetIterator& a, const ESetIterator& b) noexcept
300 {
301  return !(a < b);
302 }
303 
305 inline bool
306 operator<=(const ESetIterator& a, const ESetIterator& b) noexcept
307 {
308  return !(b < a);
309 }
310 
315 inline ESetIterator
317 {
318  return it + n;
319 }
320 
321 // Inlined methods of ESet which need ESetIterator to have been defined:
322 
323 inline ESetIterator
324 ESet::begin() const {
325  return ESetIterator(*this, size());
326 }
327 
328 inline ESetIterator
329 ESet::end() const {
330  // Decrementing the result of end() needs to work, so we must pass in
331  // *this here.
332  return ESetIterator(*this, 0);
333 }
334 
335 inline ESetIterator
337  return ESetIterator(*this, size() - i);
338 }
339 
340 inline ESetIterator
341 ESet::back() const {
342  return ESetIterator(*this, 1);
343 }
344 
345 }
346 
347 #endif // XAPIAN_INCLUDED_ESET_H
Compiler attribute macros.
Iterator over a Xapian::ESet.
Definition: eset.h:157
ESetIterator operator-(difference_type n) const
Return the iterator decremented by n positions.
Definition: eset.h:253
ESetIterator & operator++()
Advance the iterator to the next position.
Definition: eset.h:181
Xapian::termcount_diff difference_type
Definition: eset.h:222
ESetIterator operator--(int)
Move the iterator to the previous position (postfix version).
Definition: eset.h:200
Xapian::ESet eset
Definition: eset.h:165
Xapian::ESet::size_type off_from_end
Definition: eset.h:172
ESetIterator & operator-=(difference_type n)
Move the iterator back by n positions.
Definition: eset.h:236
value_type * pointer
Definition: eset.h:224
difference_type operator-(const ESetIterator &o) const
Return the number of positions between o and this iterator.
Definition: eset.h:258
ESetIterator operator+(difference_type n) const
Return the iterator incremented by n positions.
Definition: eset.h:245
ESetIterator()
Create an unpositioned ESetIterator.
Definition: eset.h:175
ESetIterator operator++(int)
Advance the iterator to the next position (postfix version).
Definition: eset.h:187
std::random_access_iterator_tag iterator_category
Definition: eset.h:218
ESetIterator & operator--()
Move the iterator to the previous position.
Definition: eset.h:194
std::string value_type
Definition: eset.h:220
value_type reference
Definition: eset.h:226
ESetIterator(const Xapian::ESet &eset_, Xapian::termcount off_from_end_)
Definition: eset.h:160
ESetIterator & operator+=(difference_type n)
Move the iterator forwards by n positions.
Definition: eset.h:230
Class which actually implements Xapian::ESet.
Definition: esetinternal.h:80
Class representing a list of search results.
Definition: eset.h:42
value_type reference
Definition: eset.h:136
Xapian::termcount size_type
Definition: eset.h:124
Xapian::ESetIterator const_iterator
Definition: eset.h:130
Xapian::termcount size() const
Return number of items in this ESet object.
const value_type * const_pointer
Definition: eset.h:134
ESetIterator back() const
Return iterator pointing to the last object in this ESet.
Definition: eset.h:341
ESet & operator=(ESet &&o)
Move assignment operator.
Xapian::ESetIterator value_type
Definition: eset.h:122
Xapian::ESetIterator iterator
Definition: eset.h:128
ESet & operator=(const ESet &o)
Copying is allowed.
ESetIterator end() const
Return iterator pointing to just after the last item in this ESet.
Definition: eset.h:329
const value_type const_reference
Definition: eset.h:138
Xapian::termcount_diff difference_type
Definition: eset.h:126
Xapian::Internal::intrusive_ptr_nonnull< Internal > internal
Definition: eset.h:47
friend class ESetIterator
Definition: eset.h:43
ESetIterator operator[](Xapian::termcount i) const
Return iterator pointing to the i-th object in this ESet.
Definition: eset.h:336
Xapian::termcount max_size() const
Definition: eset.h:152
value_type * pointer
Definition: eset.h:132
void swap(ESet &o)
Efficiently swap this ESet object with another.
Definition: eset.h:92
bool empty() const
Return true if this ESet object is empty.
Definition: eset.h:82
ESet(const ESet &o)
Copying is allowed.
ESet(ESet &&o)
Move constructor.
ESetIterator begin() const
Return iterator pointing to the first item in this ESet.
Definition: eset.h:324
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
bool operator>(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:292
XAPIAN_TERMCOUNT_BASE_TYPE termcount_diff
A signed difference between two counts of terms.
Definition: types.h:71
bool operator>=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:299
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:64
bool operator<=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:306
bool operator==(const ESetIterator &a, const ESetIterator &b) noexcept
Equality test for ESetIterator objects.
Definition: eset.h:271
bool operator!=(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:278
ESetIterator operator+(ESetIterator::difference_type n, const ESetIterator &it)
Return ESetIterator it incremented by n positions.
Definition: eset.h:316
bool operator<(const ESetIterator &a, const ESetIterator &b) noexcept
Inequality test for ESetIterator objects.
Definition: eset.h:285
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
Definition: query.h:827
stemming algorithms
typedefs for Xapian
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28