api/ompostlistiterator.cc

Go to the documentation of this file.
00001 /* ompostlistiterator.cc
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2003,2004,2005 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/postingiterator.h>
00024 #include <xapian/positioniterator.h>
00025 #include "postlist.h"
00026 #include "omassert.h"
00027 #include "omdebug.h"
00028 
00029 using namespace std;
00030 
00031 Xapian::PostingIterator::PostingIterator(Internal *internal_)
00032         : internal(internal_)
00033 {
00034     if (internal.get()) {
00035         // A PostList starts before the start, iterators start at the start
00036         Internal *p = internal->next();
00037         if (p) internal = p; // handle prune
00038         if (internal->at_end()) internal = 0;
00039     }
00040 }
00041 
00042 Xapian::PostingIterator::PostingIterator() : internal(0) {
00043     DEBUGAPICALL(void, "Xapian::PostingIterator::PostingIterator", "");
00044 }
00045 
00046 Xapian::PostingIterator::~PostingIterator() {
00047     DEBUGAPICALL(void, "Xapian::PostingIterator::~PostingIterator", "");
00048 }
00049 
00050 Xapian::PostingIterator::PostingIterator(const Xapian::PostingIterator &other)
00051     : internal(other.internal)
00052 {
00053     DEBUGAPICALL(void, "Xapian::PostingIterator::Xapian::PostingIterator", other);
00054 }
00055 
00056 void
00057 Xapian::PostingIterator::operator=(const Xapian::PostingIterator &other)
00058 {
00059     DEBUGAPICALL(void, "Xapian::PostingIterator::operator=", other);
00060     internal = other.internal;
00061 }
00062 
00063 Xapian::docid
00064 Xapian::PostingIterator::operator *() const
00065 {
00066     DEBUGAPICALL(Xapian::docid, "Xapian::PostingIterator::operator*", "");
00067     Assert(internal.get());
00068     Assert(!internal->at_end());
00069     RETURN(internal->get_docid());
00070 }
00071 
00072 Xapian::PostingIterator &
00073 Xapian::PostingIterator::operator++()
00074 {
00075     DEBUGAPICALL(void, "Xapian::PostingIterator::operator++", "");
00076     Assert(internal.get());
00077     Assert(!internal->at_end());
00078     Internal *p = internal->next();
00079     if (p) internal = p; // handle prune
00080     if (internal->at_end()) internal = 0;
00081     return *this;
00082 }
00083 
00084 // extra method, not required to be an input_iterator
00085 void
00086 Xapian::PostingIterator::skip_to(Xapian::docid did)
00087 {
00088     DEBUGAPICALL(void, "Xapian::PostingIterator::skip_to", did);
00089     Assert(internal.get());
00090     Assert(!internal->at_end());
00091     PostList *p = internal->skip_to(did, 0);
00092     if (p) internal = p; // handle prune
00093     if (internal->at_end()) internal = 0;
00094 }    
00095 
00096 // need to set Xapian::Weight object for this to work
00097 //Xapian::weight
00098 //Xapian::PostingIterator::get_weight() const
00099 //{
00100 //    DEBUGAPICALL(Xapian::weight, "Xapian::PostingIterator::get_weight", "");
00101 //    RETURN(internal->get_weight());
00102 //}
00103     
00104 Xapian::doclength
00105 Xapian::PostingIterator::get_doclength() const
00106 {
00107     DEBUGAPICALL(Xapian::doclength, "Xapian::PostingIterator::get_doclength", "");
00108     Assert(internal.get());
00109     Assert(!internal->at_end());
00110     RETURN(internal->get_doclength());
00111 }
00112 
00113 Xapian::termcount
00114 Xapian::PostingIterator::get_wdf() const
00115 {
00116     DEBUGAPICALL(Xapian::termcount, "Xapian::PostingIterator::get_wdf", "");
00117     Assert(internal.get());
00118     Assert(!internal->at_end());
00119     RETURN(internal->get_wdf());
00120 }
00121 
00122 Xapian::PositionIterator
00123 Xapian::PostingIterator::positionlist_begin() const
00124 {
00125     DEBUGAPICALL(Xapian::PositionIterator, "Xapian::PostingIterator::positionlist_begin", "");
00126     Assert(internal.get());
00127     Assert(!internal->at_end());
00128     RETURN(Xapian::PositionIterator(internal->open_position_list()));
00129 }
00130 
00131 string
00132 Xapian::PostingIterator::get_description() const
00133 {
00135     string desc = "Xapian::PostingIterator([pos=";
00136     if (internal.get() == 0) {
00137         desc += "END";
00138     } else {
00139         desc += internal->get_description();
00140     }
00141     desc += "])";
00142     return desc;
00143 }

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