xapian-core  1.4.25
termiterator.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/termiterator.h"
24 
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "termlist.h"
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 void
34 TermIterator::decref()
35 {
36  Assert(internal);
37  if (--internal->_refs == 0)
38  delete internal;
39 }
40 
41 void
42 TermIterator::post_advance(Internal * res)
43 {
44  if (res) {
45  // This can happen with iterating allterms from multiple databases.
46  ++res->_refs;
47  decref();
48  internal = res;
49  }
50  if (internal->at_end()) {
51  decref();
52  internal = NULL;
53  }
54 }
55 
56 TermIterator::TermIterator(Internal *internal_) : internal(internal_)
57 {
58  LOGCALL_CTOR(API, "TermIterator", internal_);
59  if (!internal) return;
60  try {
61  ++internal->_refs;
63  } catch (...) {
64  // The destructor only runs if the constructor completes, so we have to
65  // take care of cleaning up for ourselves here.
66  decref();
67  throw;
68  }
69 }
70 
72  : internal(o.internal)
73 {
74  LOGCALL_CTOR(API, "TermIterator", o);
75  if (internal)
76  ++internal->_refs;
77 }
78 
81 {
82  LOGCALL(API, TermIterator &, "TermIterator::operator=", o);
83  if (o.internal)
84  ++o.internal->_refs;
85  if (internal)
86  decref();
87  internal = o.internal;
88  RETURN(*this);
89 }
90 
91 string
93 {
94  LOGCALL(API, string, "TermIterator::operator*", NO_ARGS);
95  Assert(internal);
97 }
98 
101 {
102  LOGCALL(API, TermIterator &, "TermIterator::operator++", NO_ARGS);
103  Assert(internal);
105  RETURN(*this);
106 }
107 
110 {
111  LOGCALL(API, Xapian::termcount, "TermIterator::get_wdf", NO_ARGS);
112  Assert(internal);
113  RETURN(internal->get_wdf());
114 }
115 
118 {
119  LOGCALL(API, Xapian::doccount, "TermIterator::get_termfreq", NO_ARGS);
120  Assert(internal);
122 }
123 
126 {
127  LOGCALL(API, Xapian::termcount, "TermIterator::positionlist_count", NO_ARGS);
128  Assert(internal);
130 }
131 
134 {
135  LOGCALL(API, PositionIterator, "TermIterator::positionlist_begin", NO_ARGS);
136  Assert(internal);
138 }
139 
140 void
141 TermIterator::skip_to(const string & term)
142 {
143  LOGCALL_VOID(API, "TermIterator::skip_to", term);
144  if (internal)
145  post_advance(internal->skip_to(term));
146 }
147 
148 std::string
150 {
151 #if 0 // FIXME: Add TermIterator::Internal::get_description() method.
152  string desc = "TermIterator(";
153  if (internal)
154  desc += internal->get_description();
155  desc += ')';
156  return desc;
157 #else
158  return "TermIterator()";
159 #endif
160 }
161 
162 }
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 Xapian::termcount get_wdf() const =0
Return the wdf for the term at the current position.
virtual Internal * next()=0
Advance the current position to the next term in the termlist.
virtual Xapian::doccount get_termfreq() const =0
Return the term frequency for the term at the current position.
unsigned _refs
Reference count.
Definition: intrusive_ptr.h:73
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
virtual Internal * skip_to(const std::string &term)=0
Skip forward to the specified term.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:488
void skip_to(const std::string &term)
Advance the iterator to term term.
Abstract base class for termlists.
Definition: termlist.h:39
STL namespace.
TermIterator & operator=(const TermIterator &o)
Assignment.
Definition: termiterator.cc:80
Class for iterating over a list of terms.
Definition: termiterator.h:41
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
TermIterator & operator++()
Advance the iterator to the next position.
TermIterator()
Default constructor.
Definition: termiterator.h:80
virtual Xapian::PositionIterator positionlist_begin() const =0
Return a PositionIterator for the current position.
Class for iterating over term positions.
virtual std::string get_termname() const =0
Return the termname at the current position.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
Abstract base class for termlists.
Various assertion macros.
virtual Xapian::termcount positionlist_count() const =0
Return the length of the position list for the current position.
Class for iterating over a list of terms.
std::string operator*() const
Return the term at the current position.
Definition: termiterator.cc:92
std::string get_description() const
Return a string describing this object.
void post_advance(Internal *res)
Definition: termiterator.cc:42
PositionIterator positionlist_begin() const
Return a PositionIterator for the current term.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487