xapian-core  1.4.26
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, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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  Assert(internal);
45  ++internal->_refs;
46  try {
47  internal->next();
48  } catch (...) {
49  // The destructor only runs if the constructor completes, so we have to
50  // take care of cleaning up for ourselves here.
51  decref();
52  throw;
53  }
54  if (internal->at_end()) {
55  decref();
56  internal = NULL;
57  }
58 }
59 
61  : internal(o.internal)
62 {
63  LOGCALL_CTOR(API, "ValueIterator", o);
64  if (internal)
65  ++internal->_refs;
66 }
67 
70 {
71  LOGCALL(API, ValueIterator &, "ValueIterator::operator=", o);
72  if (o.internal)
73  ++o.internal->_refs;
74  if (internal)
75  decref();
76  internal = o.internal;
77  RETURN(*this);
78 }
79 
80 string
82 {
83  LOGCALL(API, string, "ValueIterator::operator*", NO_ARGS);
84  Assert(internal);
86 }
87 
90 {
91  LOGCALL(API, ValueIterator &, "ValueIterator::operator++", NO_ARGS);
92  Assert(internal);
93  internal->next();
94  if (internal->at_end()) {
95  decref();
96  internal = NULL;
97  }
98  RETURN(*this);
99 }
100 
103 {
104  LOGCALL(API, Xapian::docid, "ValueIterator::get_docid", NO_ARGS);
105  Assert(internal);
107 }
108 
111 {
112  LOGCALL(API, Xapian::valueno, "ValueIterator::get_valueno", NO_ARGS);
113  Assert(internal);
115 }
116 
117 void
119 {
120  LOGCALL_VOID(API, "ValueIterator::skip_to", docid_or_slot);
121  if (internal) {
122  internal->skip_to(docid_or_slot);
123  if (internal->at_end()) {
124  decref();
125  internal = NULL;
126  }
127  }
128 }
129 
130 bool
132 {
133  LOGCALL(API, bool, "ValueIterator::check", did);
134  if (internal) {
135  if (!internal->check(did)) RETURN(false);
136  if (internal->at_end()) {
137  decref();
138  internal = NULL;
139  }
140  }
141  RETURN(true);
142 }
143 
144 std::string
146 {
147  string desc = "ValueIterator(";
148  if (internal)
149  desc += internal->get_description();
150  desc += ')';
151  return desc;
152 }
153 
154 }
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
virtual bool at_end() const =0
Return true if the current position is past the last entry in this list.
unsigned _refs
Reference count.
Definition: intrusive_ptr.h:73
Class for iterating over document values.
Definition: valueiterator.h:40
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:488
STL namespace.
std::string operator*() const
Return the value at the current position.
ValueIterator & operator++()
Advance the iterator to the next position.
virtual Xapian::valueno get_valueno() const =0
Return the value slot for the current position/this iterator.
ValueIterator & operator=(const ValueIterator &o)
Assignment.
Class for iterating over document values.
virtual Xapian::docid get_docid() const =0
Return the docid at the current position.
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
ValueIterator()
Default constructor.
Definition: valueiterator.h:81
bool check(Xapian::docid docid)
Check if the specified docid occurs.
Abstract base class for value streams.
Definition: valuelist.h:31
virtual std::string get_value() const =0
Return the value at the current position.
unsigned valueno
The number for a value slot in a document.
Definition: types.h:108
Xapian::docid get_docid() const
Return the docid at the current position.
virtual bool check(Xapian::docid did)
Check if the specified docid occurs in this valuestream.
Definition: valuelist.cc:30
Abstract base class for value streams.
Various assertion macros.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
std::string get_description() const
Return a string describing this object.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487
Xapian::valueno get_valueno() const
Return the value slot number for the current position.
void skip_to(Xapian::docid docid_or_slot)
Advance the iterator to document id or value slot docid_or_slot.