# include/xapian/positioniterator.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 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_POSITIONITERATOR_H
    00027 #define XAPIAN_INCLUDED_POSITIONITERATOR_H
    00028
    00029 #include <iterator>
    00030 #include <string>
    00031
    00032 #include <xapian/base.h>
    00033 #include <xapian/types.h>
    00034
    00035 namespace Xapian {
    00036
    00037 class Database;
    00038 class PostingIterator;
    00039 class TermIterator;
    00040
    00044 class TermPosWrapper {
    00045     private:
    00046         termpos pos;
    00047     public:
    00048         TermPosWrapper(termpos pos_) : pos(pos_) { }
    00049         termpos operator*() const { return pos; }
    00050 };
    00051
    00054 class PositionIterator {
    00055     private:
    00056         // friend classes which need to be able to construct us
    00057         friend class PostingIterator;
    00058         friend class TermIterator;
    00059         friend class Database;
    00060
    00061     public:
    00062         class Internal;
    00064         Xapian::Internal::RefCntPtr<Internal> internal;
    00065
    00066         friend bool operator==(const PositionIterator &a, const PositionIterator &b);
    00067
    00068         // FIXME: ought to be private
    00069         explicit PositionIterator(Internal *internal_);
    00070
    00072         PositionIterator();
    00073
    00075         ~PositionIterator();
    00076
    00080         PositionIterator(const PositionIterator &o);
    00081
    00085         void operator=(const PositionIterator &o);
    00086
    00087         Xapian::termpos operator *() const;
    00088
    00089         PositionIterator & operator++();
    00090
    00091         TermPosWrapper operator++(int) {
    00092             Xapian::termpos tmp = **this;
    00093             operator++();
    00094             return TermPosWrapper(tmp);
    00095         }
    00096
    00097         // extra method, not required for an input_iterator
    00098         void skip_to(Xapian::termpos pos);
    00099
    00103         std::string get_description() const;
    00104
    00105         // Allow use as an STL iterator
    00106         typedef std::input_iterator_tag iterator_category;
    00107         typedef Xapian::termpos value_type;
    00108         typedef Xapian::termpos_diff difference_type;  // "om_termposcount"
    00109         typedef Xapian::termpos * pointer;
    00110         typedef Xapian::termpos & reference;
    00111 };
    00112
    00114 inline bool
    00115 operator==(const PositionIterator &a, const PositionIterator &b)
    00116 {
    00117     return (a.internal.get() == b.internal.get());
    00118 }
    00119
    00121 inline bool
    00122 operator!=(const PositionIterator &a, const PositionIterator &b)
    00123 {
    00124     return !(a == b);
    00125 }
    00126
    00127 }
    00128
    00129 #endif /* XAPIAN_INCLUDED_POSITIONITERATOR_H */