xapian-core  1.4.25
positioniterator.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 
24 
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "backends/positionlist.h"
28 
29 using namespace std;
30 
31 namespace Xapian {
32 
33 void
34 PositionIterator::decref()
35 {
36  Assert(internal);
37  if (--internal->_refs == 0)
38  delete internal;
39 }
40 
41 PositionIterator::PositionIterator(Internal *internal_) : internal(internal_)
42 {
43  LOGCALL_CTOR(API, "PositionIterator", internal_);
44  Assert(internal);
45  ++internal->_refs;
46  try {
47  if (!internal->next()) {
48  decref();
49  internal = NULL;
50  }
51  } catch (...) {
52  // The destructor only runs if the constructor completes, so we have to
53  // take care of cleaning up for ourselves here.
54  decref();
55  throw;
56  }
57 }
58 
60  : internal(o.internal)
61 {
62  LOGCALL_CTOR(API, "PositionIterator", o);
63  if (internal)
64  ++internal->_refs;
65 }
66 
69 {
70  LOGCALL(API, PositionIterator &, "PositionIterator::operator=", o);
71  if (o.internal)
72  ++o.internal->_refs;
73  if (internal)
74  decref();
75  internal = o.internal;
76  RETURN(*this);
77 }
78 
81 {
82  LOGCALL(API, Xapian::termpos, "PositionIterator::operator*", NO_ARGS);
83  Assert(internal);
85 }
86 
89 {
90  LOGCALL(API, PositionIterator &, "PositionIterator::operator++", NO_ARGS);
91  Assert(internal);
92  if (!internal->next()) {
93  decref();
94  internal = NULL;
95  }
96  RETURN(*this);
97 }
98 
99 void
101 {
102  LOGCALL_VOID(API, "PositionIterator::skip_to", pos);
103  if (internal) {
104  if (!internal->skip_to(pos)) {
105  decref();
106  internal = NULL;
107  }
108  }
109 }
110 
111 std::string
113 {
114 #if 0 // FIXME: Add PositionIterator::Internal::get_description() method.
115  string desc = "PositionIterator(";
116  if (internal)
117  desc += internal->get_description();
118  desc += ')';
119  return desc;
120 #else
121  return "PositionIterator()";
122 #endif
123 }
124 
125 }
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
void skip_to(Xapian::termpos termpos)
Advance the iterator to term position termpos.
Xapian::termpos operator*() const
Return the term position at the current iterator position.
unsigned _refs
Reference count.
Definition: intrusive_ptr.h:73
virtual bool next()=0
Advance to the next entry in the positionlist.
PositionIterator & operator++()
Advance the iterator to the next position.
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Definition: debuglog.h:488
Abstract base class for iterating term positions in a document.
STL namespace.
Class for iterating over term positions.
virtual bool skip_to(Xapian::termpos termpos)=0
Skip forward to the specified position.
Class for iterating over term positions.
virtual Xapian::termpos get_position() const =0
Return the current position.
std::string get_description() const
Return a string describing this object.
#define LOGCALL_CTOR(CATEGORY, CLASS, PARAMS)
Definition: debuglog.h:489
unsigned XAPIAN_TERMPOS_BASE_TYPE termpos
A term position within a document or query.
Definition: types.h:83
Various assertion macros.
Abstract base class for iterating term positions in a document.
Definition: positionlist.h:31
PositionIterator & operator=(const PositionIterator &o)
Assignment.
PositionIterator()
Default constructor.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487