xapian-core  2.0.0
valueiterator.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2010,2011,2012,2013,2014,2015 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_VALUEITERATOR_H
22 #define XAPIAN_INCLUDED_VALUEITERATOR_H
23 
24 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
25 # error Never use <xapian/valueiterator.h> directly; include <xapian.h> instead.
26 #endif
27 
28 #include <iterator>
29 #include <string>
30 
31 #include <xapian/attributes.h>
32 #include <xapian/derefwrapper.h>
33 #include <xapian/types.h>
34 #include <xapian/visibility.h>
35 
36 namespace Xapian {
37 
40  void decref();
41 
42  public:
44  class Internal;
46  Internal * internal;
47 
50  explicit ValueIterator(Internal *internal_);
51 
53  ValueIterator(const ValueIterator & o);
54 
56  ValueIterator & operator=(const ValueIterator & o);
57 
60  : internal(o.internal) {
61  o.internal = nullptr;
62  }
63 
66  if (this != &o) {
67  if (internal) decref();
68  internal = o.internal;
69  o.internal = nullptr;
70  }
71  return *this;
72  }
73 
79  ValueIterator() noexcept
80  : internal() { }
81 
84  if (internal) decref();
85  }
86 
88  std::string operator*() const;
89 
91  ValueIterator & operator++();
92 
95  const std::string & value(**this);
96  operator++();
97  return DerefWrapper_<std::string>(value);
98  }
99 
105  Xapian::docid get_docid() const;
106 
113  Xapian::valueno get_valueno() const;
114 
133  void skip_to(Xapian::docid docid_or_slot);
134 
159 #ifndef check
160  bool check(Xapian::docid docid);
161 #else
162  // The AssertMacros.h header in the macOS SDK currently defines a check
163  // macro. Apple have deprecated check() in favour of __Check() and
164  // plan to remove check() in a "future release", but for now prevent
165  // expansion of check by adding parentheses in the method prototype:
166  // https://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
167  //
168  // We do this conditionally, as these parentheses trip up SWIG's
169  // parser:
170  // https://github.com/swig/swig/issues/45
171  bool (check)(Xapian::docid docid);
172 #endif
173 
175  std::string get_description() const;
176 
187  // @{
189  typedef std::input_iterator_tag iterator_category;
191  typedef std::string value_type;
195  typedef value_type* pointer;
198  // @}
199 };
200 
202 inline bool
203 operator==(const ValueIterator& a, const ValueIterator& b) noexcept
204 {
205  // Use a pointer comparison - this ensures both that (a == a) and correct
206  // handling of end iterators (which we ensure have NULL internals).
207  return a.internal == b.internal;
208 }
209 
211 inline bool
212 operator!=(const ValueIterator& a, const ValueIterator& b) noexcept
213 {
214  return !(a == b);
215 }
216 
217 }
218 
219 #endif // XAPIAN_INCLUDED_VALUEITERATOR_H
Compiler attribute macros.
Abstract base class for value streams.
Definition: valuelist.h:31
Class for iterating over document values.
Definition: valueiterator.h:39
std::input_iterator_tag iterator_category
ValueIterator() noexcept
Default constructor.
Definition: valueiterator.h:79
Xapian::doccount_diff difference_type
~ValueIterator()
Destructor.
Definition: valueiterator.h:83
ValueIterator(ValueIterator &&o)
Move constructor.
Definition: valueiterator.h:59
DerefWrapper_< std::string > operator++(int)
Advance the iterator to the next position (postfix version).
Definition: valueiterator.h:94
ValueIterator & operator=(ValueIterator &&o)
Move assignment operator.
Definition: valueiterator.h:65
Class for wrapping type returned by an input_iterator.
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
XAPIAN_DOCID_BASE_TYPE doccount_diff
A signed difference between two counts of documents.
Definition: types.h:44
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
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
const Query operator*(double factor, const Query &q)
Scale a Xapian::Query object using OP_SCALE_WEIGHT.
Definition: query.h:827
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
typedefs for Xapian
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29