# include/xapian/postingiterator.h

Go to the documentation of this file.

    00001
    00004 /* ----START-LICENCE----
    00005  * Copyright 1999,2000,2001 BrightStation PLC
    00006  * Copyright 2002 Ananova Ltd
    00007  * Copyright 2003,2004,2005 Olly Betts
    00008  *
    00009  * This program is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU General Public License as
    00011  * published by the Free Software Foundation; either version 2 of the
    00012  * License, or (at your option) any later version.
    00013  *
    00014  * This program is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017  * GNU General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU General Public License
    00020  * along with this program; if not, write to the Free Software
    00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00022  * USA
    00023  * -----END-LICENCE-----
    00024  */
    00025
    00026 #ifndef XAPIAN_INCLUDED_POSTINGITERATOR_H
    00027 #define XAPIAN_INCLUDED_POSTINGITERATOR_H
    00028
    00029 #include <iterator>
    00030 #include <string>
    00031
    00032 #include <xapian/base.h>
    00033 #include <xapian/types.h>
    00034 #include <xapian/positioniterator.h>
    00035
    00036 namespace Xapian {
    00037
    00038 class Database;
    00039
    00043 class DocIDWrapper {
    00044     private:
    00045         docid did;
    00046     public:
    00047         DocIDWrapper(docid did_) : did(did_) { }
    00048         docid operator*() const { return did; }
    00049 };
    00050
    00053 class PostingIterator {
    00054     public:
    00055         class Internal;
    00057         Xapian::Internal::RefCntPtr<Internal> internal;
    00058
    00059     private:
    00060         friend class Database; // So Database can construct us
    00061
    00062         explicit PostingIterator(Internal *internal_);
    00063
    00064     public:
    00065         friend bool operator==(const PostingIterator &a,
    00066                                const PostingIterator &b);
    00067
    00069         PostingIterator();
    00070
    00072         ~PostingIterator();
    00073
    00077         PostingIterator(const PostingIterator &other);
    00078
    00082         void operator=(const PostingIterator &other);
    00083
    00084         PostingIterator & operator++();
    00085
    00086         DocIDWrapper operator++(int) {
    00087             Xapian::docid tmp = **this;
    00088             operator++();
    00089             return DocIDWrapper(tmp);
    00090         }
    00091
    00095         void skip_to(Xapian::docid did);
    00096
    00097 // Get the weight of the posting at the current position: will
    00098 // need to set a weight object for this to work.
    00099 // Xapian::weight get_weight() const;
    00100
    00102         Xapian::docid operator *() const;
    00103
    00113         Xapian::doclength get_doclength() const;
    00114
    00118         Xapian::termcount get_wdf() const;
    00119
    00123         PositionIterator positionlist_begin() const;
    00124
    00128         PositionIterator positionlist_end() const {
    00129             return PositionIterator(NULL);
    00130         }
    00131
    00132         // Don't expose these methods here.  A container iterator doesn't
    00133         // provide a method to find the size of the container...
    00134         // Xapian::doccount get_termfreq() const;
    00135         // Xapian::termcount get_collection_freq() const;
    00136
    00140         std::string get_description() const;
    00141
    00143
    00144         typedef std::input_iterator_tag iterator_category;
    00145         typedef Xapian::docid value_type;
    00146         typedef Xapian::doccount_diff difference_type;
    00147         typedef Xapian::docid * pointer;
    00148         typedef Xapian::docid & reference;
    00150 };
    00151
    00153 inline bool operator==(const PostingIterator &a, const PostingIterator &b)
    00154 {
    00155     return (a.internal.get() == b.internal.get());
    00156 }
    00157
    00159 inline bool operator!=(const PostingIterator &a, const PostingIterator &b)
    00160 {
    00161     return !(a == b);
    00162 }
    00163
    00164 }
    00165
    00166 #endif /* XAPIAN_INCLUDED_POSTINGITERATOR_H */