include/xapian/positioniterator.h

Go to the documentation of this file.
00001 
00004 /* Copyright 1999,2000,2001 BrightStation PLC
00005  * Copyright 2002 Ananova Ltd
00006  * Copyright 2003,2004,2007 Olly Betts
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00021  * USA
00022  */
00023 
00024 #ifndef XAPIAN_INCLUDED_POSITIONITERATOR_H
00025 #define XAPIAN_INCLUDED_POSITIONITERATOR_H
00026 
00027 #include <iterator>
00028 #include <string>
00029 
00030 #include <xapian/base.h>
00031 #include <xapian/types.h>
00032 #include <xapian/visibility.h>
00033 
00034 namespace Xapian {
00035 
00036 class Database;
00037 class PostingIterator;
00038 class TermIterator;
00039 
00043 class TermPosWrapper {
00044     private:
00045         termpos pos;
00046     public:
00047         explicit TermPosWrapper(termpos pos_) : pos(pos_) { }
00048         termpos operator*() const { return pos; }
00049 };
00050 
00053 class XAPIAN_VISIBILITY_DEFAULT PositionIterator {
00054     private:
00055         // friend classes which need to be able to construct us
00056         friend class PostingIterator;
00057         friend class TermIterator;
00058         friend class Database;
00059 
00060     public:
00061         class Internal;
00063         Xapian::Internal::RefCntPtr<Internal> internal;
00064 
00065         friend bool operator==(const PositionIterator &a, const PositionIterator &b);
00066 
00067         // FIXME: ought to be private
00068         explicit PositionIterator(Internal *internal_);
00069 
00071         PositionIterator();
00072 
00074         ~PositionIterator();
00075 
00079         PositionIterator(const PositionIterator &o);
00080 
00084         void operator=(const PositionIterator &o);
00085 
00086         Xapian::termpos operator *() const;
00087 
00088         PositionIterator & operator++();
00089 
00090         TermPosWrapper operator++(int) {
00091             Xapian::termpos tmp = **this;
00092             operator++();
00093             return TermPosWrapper(tmp);
00094         }
00095 
00096         // extra method, not required for an input_iterator
00097         void skip_to(Xapian::termpos pos);
00098 
00100         std::string get_description() const;
00101 
00102         // Allow use as an STL iterator
00103         typedef std::input_iterator_tag iterator_category;
00104         typedef Xapian::termpos value_type;
00105         typedef Xapian::termpos_diff difference_type;  // "om_termposcount"
00106         typedef Xapian::termpos * pointer;
00107         typedef Xapian::termpos & reference;
00108 };
00109 
00111 inline bool
00112 operator==(const PositionIterator &a, const PositionIterator &b)
00113 {
00114     return (a.internal.get() == b.internal.get());
00115 }
00116 
00118 inline bool
00119 operator!=(const PositionIterator &a, const PositionIterator &b)
00120 {
00121     return !(a == b);
00122 }
00123 
00124 }
00125 
00126 #endif /* XAPIAN_INCLUDED_POSITIONITERATOR_H */

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