File: omtermlistiterator.cc

package info (click to toggle)
xapian-core 1.2.19-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 19,420 kB
  • ctags: 12,656
  • sloc: cpp: 101,561; sh: 11,340; ansic: 8,193; perl: 757; makefile: 635; tcl: 308; python: 40
file content (145 lines) | stat: -rw-r--r-- 4,050 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* omtermlistiterator.cc
 *
 * Copyright 1999,2000,2001 BrightStation PLC
 * Copyright 2003,2004,2005,2006,2007,2008 Olly Betts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#include <config.h>
#include <xapian/termiterator.h>
#include "termlist.h"
#include "positionlist.h"
#include "debuglog.h"
#include "omassert.h"

using namespace std;

// Helper function.
inline void
handle_prune(Xapian::Internal::RefCntPtr<TermList>& old, TermList * result)
{
    if (result) {
	old = result;
    }
}

Xapian::TermIterator::TermIterator(Internal *internal_)
	: internal(internal_)
{
    if (internal.get()) {
	// A TermList starts before the start, iterators start at the start
	handle_prune(internal, internal->next());
	if (internal->at_end()) internal = 0;
    }
}

Xapian::TermIterator::TermIterator() : internal(0)
{
    LOGCALL_VOID(API, "Xapian::TermIterator::TermIterator", NO_ARGS);
}

Xapian::TermIterator::~TermIterator() {
    LOGCALL_VOID(API, "Xapian::TermIterator::~TermIterator", NO_ARGS);
}

Xapian::TermIterator::TermIterator(const Xapian::TermIterator &other)
    : internal(other.internal)
{
    LOGCALL_VOID(API, "Xapian::TermIterator::TermIterator", other);
}

void
Xapian::TermIterator::operator=(const Xapian::TermIterator &other)
{
    LOGCALL_VOID(API, "Xapian::TermIterator::operator=", other);
    internal = other.internal;
}

string
Xapian::TermIterator::operator *() const
{
    LOGCALL(API, string, "Xapian::TermIterator::operator*", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    RETURN(internal->get_termname());
}

Xapian::termcount
Xapian::TermIterator::get_wdf() const
{
    LOGCALL(API, Xapian::termcount, "Xapian::TermIterator::get_wdf", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    RETURN(internal->get_wdf());
}

Xapian::doccount
Xapian::TermIterator::get_termfreq() const
{
    LOGCALL(API, Xapian::doccount, "Xapian::TermIterator::get_termfreq", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    RETURN(internal->get_termfreq());
}

Xapian::TermIterator &
Xapian::TermIterator::operator++()
{
    LOGCALL_VOID(API, "Xapian::TermIterator::operator++", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    handle_prune(internal, internal->next());
    if (internal->at_end()) internal = 0;
    return *this;
}

// extra method, not required to be an input_iterator
void
Xapian::TermIterator::skip_to(const string & tname)
{
    LOGCALL_VOID(API, "Xapian::TermIterator::skip_to", tname);
    if (internal.get()) {
	Assert(!internal->at_end());
	handle_prune(internal, internal->skip_to(tname));
	if (internal->at_end()) internal = 0;
    }
}

Xapian::termcount
Xapian::TermIterator::positionlist_count() const
{
    LOGCALL(API, Xapian::termcount, "Xapian::TermIterator::positionlist_count", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    RETURN(internal->positionlist_count());
}

Xapian::PositionIterator
Xapian::TermIterator::positionlist_begin() const
{
    LOGCALL(API, Xapian::PositionIterator, "Xapian::TermIterator::positionlist_begin", NO_ARGS);
    Assert(internal.get());
    Assert(!internal->at_end());
    RETURN(internal->positionlist_begin());
}

std::string
Xapian::TermIterator::get_description() const
{
    /// \todo display contents of the object
    return "Xapian::TermIterator()";
}