00001 00004 /* Copyright 1999,2000,2001 BrightStation PLC 00005 * Copyright 2002 Ananova Ltd 00006 * Copyright 2003,2004,2007,2009,2012 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/derefwrapper.h> 00032 #include <xapian/types.h> 00033 #include <xapian/visibility.h> 00034 00035 namespace Xapian { 00036 00037 class Database; 00038 class PostingIterator; 00039 class TermIterator; 00040 00043 class XAPIAN_VISIBILITY_DEFAULT PositionIterator { 00044 private: 00045 // friend classes which need to be able to construct us 00046 friend class PostingIterator; 00047 friend class TermIterator; 00048 friend class Database; 00049 00050 public: 00051 class Internal; 00053 Xapian::Internal::RefCntPtr<Internal> internal; 00054 00055 friend bool operator==(const PositionIterator &a, const PositionIterator &b); 00056 00057 // FIXME: ought to be private 00058 explicit PositionIterator(Internal *internal_); 00059 00061 PositionIterator(); 00062 00064 ~PositionIterator(); 00065 00069 PositionIterator(const PositionIterator &o); 00070 00074 void operator=(const PositionIterator &o); 00075 00077 Xapian::termpos operator *() const; 00078 00080 PositionIterator & operator++(); 00081 00083 DerefWrapper_<termpos> operator++(int) { 00084 Xapian::termpos tmp = **this; 00085 operator++(); 00086 return DerefWrapper_<termpos>(tmp); 00087 } 00088 00095 void skip_to(Xapian::termpos pos); 00096 00098 std::string get_description() const; 00099 00100 // Allow use as an STL iterator 00101 typedef std::input_iterator_tag iterator_category; 00102 typedef Xapian::termpos value_type; 00103 typedef Xapian::termpos_diff difference_type; // "om_termposcount" 00104 typedef Xapian::termpos * pointer; 00105 typedef Xapian::termpos & reference; 00106 }; 00107 00109 inline bool 00110 operator==(const PositionIterator &a, const PositionIterator &b) 00111 { 00112 return (a.internal.get() == b.internal.get()); 00113 } 00114 00116 inline bool 00117 operator!=(const PositionIterator &a, const PositionIterator &b) 00118 { 00119 return !(a == b); 00120 } 00121 00122 } 00123 00124 #endif /* XAPIAN_INCLUDED_POSITIONITERATOR_H */