api/omtermlistiterator.cc

Go to the documentation of this file.
00001 /* omtermlistiterator.cc
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2003,2004,2005,2006,2007,2008 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00019  * USA
00020  */
00021 
00022 #include <config.h>
00023 #include <xapian/termiterator.h>
00024 #include "termlist.h"
00025 #include "positionlist.h"
00026 #include "omassert.h"
00027 #include "omdebug.h"
00028 
00029 using namespace std;
00030 
00031 // Helper function.
00032 inline void
00033 handle_prune(Xapian::Internal::RefCntPtr<TermList>& old, TermList * result)
00034 {
00035     if (result) {
00036         old = result;
00037     }
00038 }
00039 
00040 Xapian::TermIterator::TermIterator(Internal *internal_)
00041         : internal(internal_)
00042 {
00043     if (internal.get()) {
00044         // A TermList starts before the start, iterators start at the start
00045         handle_prune(internal, internal->next());
00046         if (internal->at_end()) internal = 0;
00047     }
00048 }
00049 
00050 Xapian::TermIterator::TermIterator() : internal(0)
00051 {
00052     DEBUGAPICALL(void, "Xapian::TermIterator::TermIterator", "");
00053 }
00054 
00055 Xapian::TermIterator::~TermIterator() {
00056     DEBUGAPICALL(void, "Xapian::TermIterator::~TermIterator", "");
00057 }
00058 
00059 Xapian::TermIterator::TermIterator(const Xapian::TermIterator &other)
00060     : internal(other.internal)
00061 {
00062     DEBUGAPICALL(void, "Xapian::TermIterator::TermIterator", other);
00063 }
00064 
00065 void
00066 Xapian::TermIterator::operator=(const Xapian::TermIterator &other)
00067 {
00068     DEBUGAPICALL(void, "Xapian::TermIterator::operator=", other);
00069     internal = other.internal;
00070 }
00071 
00072 string
00073 Xapian::TermIterator::operator *() const
00074 {
00075     DEBUGAPICALL(string, "Xapian::TermIterator::operator*", "");
00076     Assert(internal.get());
00077     Assert(!internal->at_end());
00078     RETURN(internal->get_termname());
00079 }
00080 
00081 Xapian::termcount
00082 Xapian::TermIterator::get_wdf() const
00083 {
00084     DEBUGAPICALL(Xapian::termcount, "Xapian::TermIterator::get_wdf", "");
00085     Assert(internal.get());
00086     Assert(!internal->at_end());
00087     RETURN(internal->get_wdf());
00088 }
00089 
00090 Xapian::doccount
00091 Xapian::TermIterator::get_termfreq() const
00092 {
00093     DEBUGAPICALL(Xapian::doccount, "Xapian::TermIterator::get_termfreq", "");
00094     Assert(internal.get());
00095     Assert(!internal->at_end());
00096     RETURN(internal->get_termfreq());
00097 }
00098 
00099 Xapian::TermIterator &
00100 Xapian::TermIterator::operator++()
00101 {
00102     DEBUGAPICALL(void, "Xapian::TermIterator::operator++", "");
00103     Assert(internal.get());
00104     Assert(!internal->at_end());
00105     handle_prune(internal, internal->next());
00106     if (internal->at_end()) internal = 0;
00107     return *this;
00108 }
00109 
00110 // extra method, not required to be an input_iterator
00111 void
00112 Xapian::TermIterator::skip_to(const string & tname)
00113 {
00114     DEBUGAPICALL(void, "Xapian::TermIterator::skip_to", tname);
00115     if (internal.get()) {
00116         Assert(!internal->at_end());
00117         handle_prune(internal, internal->skip_to(tname));
00118         if (internal->at_end()) internal = 0;
00119     }
00120 }
00121 
00122 Xapian::termcount
00123 Xapian::TermIterator::positionlist_count() const
00124 {
00125     DEBUGAPICALL(Xapian::termcount, "Xapian::TermIterator::positionlist_count", "");
00126     Assert(internal.get());
00127     Assert(!internal->at_end());
00128     RETURN(internal->positionlist_count());
00129 }
00130 
00131 Xapian::PositionIterator
00132 Xapian::TermIterator::positionlist_begin() const
00133 {
00134     DEBUGAPICALL(Xapian::PositionIterator, "Xapian::TermIterator::positionlist_begin", "");
00135     Assert(internal.get());
00136     Assert(!internal->at_end());
00137     RETURN(internal->positionlist_begin());
00138 }
00139 
00140 std::string
00141 Xapian::TermIterator::get_description() const
00142 {
00144     return "Xapian::TermIterator()";
00145 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.