1 /* ompositionlistiterator.cc
2 *
3 * Copyright 1999,2000,2001 BrightStation PLC
4 * Copyright 2003,2004,2008 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (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
19 * USA
20 */
21
22 #include <config.h>
23 #include <xapian/positioniterator.h>
24 #include "positionlist.h"
25 #include "debuglog.h"
26 #include "omassert.h"
27
PositionIterator(Internal * internal_)28 Xapian::PositionIterator::PositionIterator(Internal *internal_)
29 : internal(internal_)
30 {
31 if (internal.get()) {
32 internal->next();
33 if (internal->at_end()) internal = 0;
34 }
35 }
36
PositionIterator()37 Xapian::PositionIterator::PositionIterator() : internal(0)
38 {
39 }
40
PositionIterator(const Xapian::PositionIterator & o)41 Xapian::PositionIterator::PositionIterator(const Xapian::PositionIterator &o)
42 : internal(o.internal)
43 {
44 }
45
~PositionIterator()46 Xapian::PositionIterator::~PositionIterator()
47 {
48 }
49
50 void
operator =(const Xapian::PositionIterator & o)51 Xapian::PositionIterator::operator=(const Xapian::PositionIterator &o)
52 {
53 internal = o.internal;
54 }
55
56 Xapian::termpos
operator *() const57 Xapian::PositionIterator::operator *() const
58 {
59 LOGCALL(API, Xapian::termpos, "Xapian::PositionIterator::operator*", NO_ARGS);
60 Assert(internal.get());
61 Assert(!internal->at_end());
62 RETURN(internal->get_position());
63 }
64
65 Xapian::PositionIterator &
operator ++()66 Xapian::PositionIterator::operator++()
67 {
68 LOGCALL_VOID(API, "Xapian::PositionIterator::operator++", NO_ARGS);
69 Assert(internal.get());
70 Assert(!internal->at_end());
71 internal->next();
72 if (internal->at_end()) internal = 0;
73 return *this;
74 }
75
76 // extra method, not required to be an input_iterator
77 void
skip_to(Xapian::termpos pos)78 Xapian::PositionIterator::skip_to(Xapian::termpos pos)
79 {
80 LOGCALL_VOID(API, "Xapian::PositionIterator::skip_to", pos);
81 if (!internal.get()) return;
82 Assert(!internal->at_end());
83 internal->skip_to(pos);
84 if (internal->at_end()) internal = 0;
85 }
86
87 std::string
get_description() const88 Xapian::PositionIterator::get_description() const
89 {
90 /// \todo display contents of the object
91 return "Xapian::PositionIterator()";
92 }
93