xapian-core  2.0.0
valueiterator.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2011,2013 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 #include <config.h>
22 
23 #include "xapian/valueiterator.h"
24 
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "backends/valuelist.h"
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 void
34 ValueIterator::decref()
35 {
36  Assert(internal);
37  if (--internal->_refs == 0)
38  delete internal;
39 }
40 
41 ValueIterator::ValueIterator(Internal *internal_) : internal(internal_)
42 {
43  LOGCALL_CTOR(API, "ValueIterator", internal_);
44  if (!internal)
45  return;
46  ++internal->_refs;
47  try {
48  internal->next();
49  } catch (...) {
50  // The destructor only runs if the constructor completes, so we have to
51  // take care of cleaning up for ourselves here.
52  decref();
53  throw;
54  }
55  if (internal->at_end()) {
56  decref();
57  internal = NULL;
58  }
59 }
60 
62  : internal(o.internal)
63 {
64  LOGCALL_CTOR(API, "ValueIterator", o);
65  if (internal)
66  ++internal->_refs;
67 }
68 
71 {
72  LOGCALL(API, ValueIterator &, "ValueIterator::operator=", o);
73  if (o.internal)
74  ++o.internal->_refs;
75  if (internal)
76  decref();
77  internal = o.internal;
78  RETURN(*this);
79 }
80 
81 string
83 {
84  LOGCALL(API, string, "ValueIterator::operator*", NO_ARGS);
85  Assert(internal);
87 }
88 
91 {
92  LOGCALL(API, ValueIterator &, "ValueIterator::operator++", NO_ARGS);
93  Assert(internal);
94  internal->next();
95  if (internal->at_end()) {
96  decref();
97  internal = NULL;
98  }
99  RETURN(*this);
100 }
101 
104 {
105  LOGCALL(API, Xapian::docid, "ValueIterator::get_docid", NO_ARGS);
106  Assert(internal);
108 }
109 
112 {
113  LOGCALL(API, Xapian::valueno, "ValueIterator::get_valueno", NO_ARGS);
114  Assert(internal);
116 }
117 
118 void
120 {
121  LOGCALL_VOID(API, "ValueIterator::skip_to", docid_or_slot);
122  if (internal) {
123  internal->skip_to(docid_or_slot);
124  if (internal->at_end()) {
125  decref();
126  internal = NULL;
127  }
128  }
129 }
130 
131 bool
133 {
134  LOGCALL(API, bool, "ValueIterator::check", did);
135  if (internal) {
136  if (!internal->check(did)) RETURN(false);
137  if (internal->at_end()) {
138  decref();
139  internal = NULL;
140  }
141  }
142  RETURN(true);
143 }
144 
145 std::string
147 {
148  string desc = "ValueIterator(";
149  if (internal)
150  desc += internal->get_description();
151  desc += ')';
152  return desc;
153 }
154 
155 }
unsigned _refs
Reference count.
Definition: intrusive_ptr.h:74
Abstract base class for value streams.
Definition: valuelist.h:31
virtual Xapian::docid get_docid() const =0
Return the docid at the current position.
virtual Xapian::valueno get_valueno() const =0
Return the value slot for the current position/this iterator.
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
virtual bool check(Xapian::docid did)
Check if the specified docid occurs in this valuestream.
Definition: valuelist.cc:30
virtual std::string get_value() const =0
Return the value at the current position.
Class for iterating over document values.
Definition: valueiterator.h:39
ValueIterator & operator++()
Advance the iterator to the next position.
ValueIterator() noexcept
Default constructor.
Definition: valueiterator.h:79
std::string operator*() const
Return the value at the current position.
std::string get_description() const
Return a string describing this object.
Xapian::docid get_docid() const
Return the docid at the current position.
Xapian::valueno get_valueno() const
Return the value slot number for the current position.
ValueIterator & operator=(const ValueIterator &o)
Assignment.
bool check(Xapian::docid docid)
Check if the specified docid occurs.
void skip_to(Xapian::docid docid_or_slot)
Advance the iterator to document id or value slot docid_or_slot.
Debug logging macros.
#define RETURN(...)
Definition: debuglog.h:484
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:478
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:480
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:479
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
unsigned valueno
The number for a value slot in a document.
Definition: types.h:90
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:51
Various assertion macros.
#define Assert(COND)
Definition: omassert.h:122
Class for iterating over document values.
Abstract base class for value streams.