xapian-core  1.4.21
postingiterator.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2009,2010,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/postingiterator.h"
24 
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "postlist.h"
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 void
34 PostingIterator::decref()
35 {
36  Assert(internal);
37  if (--internal->_refs == 0)
38  delete internal;
39 }
40 
41 void
42 PostingIterator::post_advance(Internal * res)
43 {
44  if (res) {
45  // FIXME: It seems this can't happen for any PostList which we wrap
46  // with PostingIterator.
47  ++res->_refs;
48  decref();
49  internal = res;
50  }
51  if (internal->at_end()) {
52  decref();
53  internal = NULL;
54  }
55 }
56 
57 PostingIterator::PostingIterator(Internal *internal_) : internal(internal_)
58 {
59  LOGCALL_CTOR(API, "PostingIterator", internal_);
60  if (!internal) return;
61  try {
62  ++internal->_refs;
64  } catch (...) {
65  // The destructor only runs if the constructor completes, so we have to
66  // take care of cleaning up for ourselves here.
67  decref();
68  throw;
69  }
70 }
71 
73  : internal(o.internal)
74 {
75  LOGCALL_CTOR(API, "PostingIterator", o);
76  if (internal)
77  ++internal->_refs;
78 }
79 
82 {
83  LOGCALL(API, PostingIterator &, "PostingIterator::operator=", o);
84  if (o.internal)
85  ++o.internal->_refs;
86  if (internal)
87  decref();
88  internal = o.internal;
89  RETURN(*this);
90 }
91 
94 {
95  LOGCALL(API, Xapian::docid, "PostingIterator::operator*", NO_ARGS);
96  Assert(internal);
98 }
99 
102 {
103  LOGCALL(API, PostingIterator &, "PostingIterator::operator++", NO_ARGS);
104  Assert(internal);
106  RETURN(*this);
107 }
108 
111 {
112  LOGCALL(API, Xapian::termcount, "PostingIterator::get_wdf", NO_ARGS);
113  Assert(internal);
114  RETURN(internal->get_wdf());
115 }
116 
119 {
120  LOGCALL(API, Xapian::termcount, "PostingIterator::get_doclength", NO_ARGS);
121  Assert(internal);
123 }
124 
127 {
128  LOGCALL(API, Xapian::termcount, "PostingIterator::get_unique_terms", NO_ARGS);
129  Assert(internal);
131 }
132 
133 #if 0 // FIXME: TermIterator supports this, so PostingIterator really ought to.
135 PostingIterator::positionlist_count() const
136 {
137  LOGCALL(API, Xapian::termcount, "PostingIterator::positionlist_count", NO_ARGS);
138  Assert(internal);
139  RETURN(internal->positionlist_count());
140 }
141 #endif
142 
145 {
146  LOGCALL(API, PositionIterator, "PostingIterator::positionlist_begin", NO_ARGS);
147  Assert(internal);
149 }
150 
151 void
153 {
154  LOGCALL_VOID(API, "PostingIterator::skip_to", did);
155  if (internal)
157 }
158 
159 std::string
161 {
162  string desc = "PostingIterator(";
163  if (internal)
164  desc += internal->get_description();
165  desc += ')';
166  return desc;
167 }
168 
169 }
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:80
PostingIterator & operator=(const PostingIterator &o)
Assignment.
#define RETURN(A)
Definition: debuglog.h:482
#define Assert(COND)
Definition: omassert.h:122
Abstract base class for postlists.
Definition: postlist.h:37
virtual Xapian::docid get_docid() const =0
Return the current docid.
Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
unsigned _refs
Reference count.
Definition: intrusive_ptr.h:73
virtual Internal * skip_to(Xapian::docid did, double w_min)=0
Skip forward to the specified docid.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:477
STL namespace.
void post_advance(Internal *res)
virtual Xapian::termcount get_unique_terms() const =0
Return the number of unique terms in the current document.
Abstract base class for postlists.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
Class for iterating over a list of terms.
PostingIterator()
Default constructor.
Xapian::docid operator*() const
Return the document id at the current position.
Class for iterating over term positions.
virtual PositionList * open_position_list() const
Read the position list for the term in the current document and return a pointer to it (not owned by ...
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:478
PositionIterator positionlist_begin() const
Return a PositionIterator for the current document.
virtual Internal * next(double w_min)=0
Advance the current position to the next document in the postlist.
virtual Xapian::termcount get_doclength() const =0
Return the length of current document.
Xapian::termcount get_doclength() const
Return the length of the document at the current position.
void skip_to(Xapian::docid did)
Advance the iterator to document did.
Class for iterating over a list of document ids.
Various assertion macros.
PostingIterator & operator++()
Advance the iterator to the next position.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Definition: types.h:52
virtual Xapian::termcount get_wdf() const
Return the wdf for the document at the current position.
Definition: postlist.cc:44
Xapian::termcount get_unique_terms() const
Return the number of unique terms in the current document.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:476
std::string get_description() const
Return a string describing this object.