Handle <title> in SVG
[xapian.git] / xapian-core / api / positioniterator.cc
blob2817d5ebb5a09a7715b0c8e48468521f2297ff5c
1 /** @file
2 * @brief Class for iterating over term positions.
3 */
4 /* Copyright (C) 2008,2009,2010,2011,2013 Olly Betts
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.
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.
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
21 #include <config.h>
23 #include "xapian/positioniterator.h"
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "backends/positionlist.h"
29 using namespace std;
31 namespace Xapian {
33 void
34 PositionIterator::decref()
36 Assert(internal);
37 if (--internal->_refs == 0)
38 delete internal;
41 PositionIterator::PositionIterator(Internal *internal_) : internal(internal_)
43 LOGCALL_CTOR(API, "PositionIterator", internal_);
44 Assert(internal);
45 ++internal->_refs;
46 try {
47 if (!internal->next()) {
48 decref();
49 internal = NULL;
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;
59 PositionIterator::PositionIterator(const PositionIterator & o)
60 : internal(o.internal)
62 LOGCALL_CTOR(API, "PositionIterator", o);
63 if (internal)
64 ++internal->_refs;
67 PositionIterator &
68 PositionIterator::operator=(const PositionIterator & o)
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);
79 Xapian::termpos
80 PositionIterator::operator*() const
82 LOGCALL(API, Xapian::termpos, "PositionIterator::operator*", NO_ARGS);
83 Assert(internal);
84 RETURN(internal->get_position());
87 PositionIterator &
88 PositionIterator::operator++()
90 LOGCALL(API, PositionIterator &, "PositionIterator::operator++", NO_ARGS);
91 Assert(internal);
92 if (!internal->next()) {
93 decref();
94 internal = NULL;
96 RETURN(*this);
99 void
100 PositionIterator::skip_to(Xapian::termpos pos)
102 LOGCALL_VOID(API, "PositionIterator::skip_to", pos);
103 if (internal) {
104 if (!internal->skip_to(pos)) {
105 decref();
106 internal = NULL;
111 std::string
112 PositionIterator::get_description() const
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