Refactor to avoid warning with GCC 12.2
[xapian.git] / xapian-core / api / termiterator.cc
blobded5980be5d32eee58941bdcb44f23a26eb45c45
1 /** @file
2 * @brief Class for iterating over a list of terms.
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/termiterator.h"
25 #include "debuglog.h"
26 #include "omassert.h"
27 #include "termlist.h"
29 using namespace std;
31 namespace Xapian {
33 void
34 TermIterator::decref()
36 Assert(internal);
37 if (--internal->_refs == 0)
38 delete internal;
41 void
42 TermIterator::post_advance(Internal * res)
44 if (res) {
45 // This can happen with iterating allterms from multiple databases.
46 ++res->_refs;
47 decref();
48 internal = res;
50 if (internal->at_end()) {
51 decref();
52 internal = NULL;
56 TermIterator::TermIterator(Internal *internal_) : internal(internal_)
58 LOGCALL_CTOR(API, "TermIterator", internal_);
59 if (!internal) return;
60 try {
61 ++internal->_refs;
62 post_advance(internal->next());
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;
71 TermIterator::TermIterator(const TermIterator & o)
72 : internal(o.internal)
74 LOGCALL_CTOR(API, "TermIterator", o);
75 if (internal)
76 ++internal->_refs;
79 TermIterator &
80 TermIterator::operator=(const TermIterator & o)
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);
91 string
92 TermIterator::operator*() const
94 LOGCALL(API, string, "TermIterator::operator*", NO_ARGS);
95 Assert(internal);
96 RETURN(internal->get_termname());
99 TermIterator &
100 TermIterator::operator++()
102 LOGCALL(API, TermIterator &, "TermIterator::operator++", NO_ARGS);
103 Assert(internal);
104 post_advance(internal->next());
105 RETURN(*this);
108 Xapian::termcount
109 TermIterator::get_wdf() const
111 LOGCALL(API, Xapian::termcount, "TermIterator::get_wdf", NO_ARGS);
112 Assert(internal);
113 RETURN(internal->get_wdf());
116 Xapian::doccount
117 TermIterator::get_termfreq() const
119 LOGCALL(API, Xapian::doccount, "TermIterator::get_termfreq", NO_ARGS);
120 Assert(internal);
121 RETURN(internal->get_termfreq());
124 Xapian::termcount
125 TermIterator::positionlist_count() const
127 LOGCALL(API, Xapian::termcount, "TermIterator::positionlist_count", NO_ARGS);
128 Assert(internal);
129 RETURN(internal->positionlist_count());
132 PositionIterator
133 TermIterator::positionlist_begin() const
135 LOGCALL(API, PositionIterator, "TermIterator::positionlist_begin", NO_ARGS);
136 Assert(internal);
137 RETURN(internal->positionlist_begin());
140 void
141 TermIterator::skip_to(const string & term)
143 LOGCALL_VOID(API, "TermIterator::skip_to", term);
144 if (internal)
145 post_advance(internal->skip_to(term));
148 std::string
149 TermIterator::get_description() const
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