00001 00004 /* Copyright (C) 2008,2009,2010 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 #ifndef XAPIAN_INCLUDED_VALUEITERATOR_H 00023 #define XAPIAN_INCLUDED_VALUEITERATOR_H 00024 00025 #include <iterator> 00026 #include <string> 00027 00028 #include <xapian/base.h> 00029 #include <xapian/derefwrapper.h> 00030 #include <xapian/types.h> 00031 #include <xapian/visibility.h> 00032 00033 namespace Xapian { 00034 00036 class ValueIteratorEnd_ { }; 00037 00039 class XAPIAN_VISIBILITY_DEFAULT ValueIterator { 00040 public: 00042 class Internal; 00044 Xapian::Internal::RefCntPtr<Internal> internal; 00045 00047 explicit ValueIterator(Internal *internal_); 00048 00050 ValueIterator(const ValueIterator & o); 00051 00053 ValueIterator(const ValueIteratorEnd_ &); 00054 00056 ValueIterator & operator=(const ValueIterator & o); 00057 00059 ValueIterator & operator=(const ValueIteratorEnd_ &); 00060 00066 ValueIterator(); 00067 00069 ~ValueIterator(); 00070 00072 std::string operator*() const; 00073 00075 ValueIterator & operator++(); 00076 00078 DerefWrapper_<std::string> operator++(int) { 00079 const std::string & value(**this); 00080 operator++(); 00081 return DerefWrapper_<std::string>(value); 00082 } 00083 00089 Xapian::docid get_docid() const; 00090 00097 Xapian::valueno get_valueno() const; 00098 00117 void skip_to(Xapian::docid docid_or_slot); 00118 00143 bool check(Xapian::docid docid); 00144 00146 std::string get_description() const; 00147 00158 // @{ 00160 typedef std::input_iterator_tag iterator_category; 00162 typedef std::string value_type; 00164 typedef Xapian::doccount_diff difference_type; 00166 typedef std::string * pointer; 00168 typedef std::string & reference; 00169 // @} 00170 }; 00171 00173 inline bool 00174 operator==(const ValueIterator &a, const ValueIterator &b) 00175 { 00176 // Use a pointer comparison - this ensures both that (a == a) and correct 00177 // handling of end iterators (which we ensure have NULL internals). 00178 return a.internal.get() == b.internal.get(); 00179 } 00180 00182 inline bool 00183 operator==(const ValueIterator &a, const ValueIteratorEnd_ &) 00184 { 00185 return a.internal.get() == NULL; 00186 } 00187 00189 inline bool 00190 operator==(const ValueIteratorEnd_ &a, const ValueIterator &b) 00191 { 00192 return b == a; 00193 } 00194 00196 inline bool 00197 operator==(const ValueIteratorEnd_ &, const ValueIteratorEnd_ &) 00198 { 00199 return true; 00200 } 00201 00203 inline bool 00204 operator!=(const ValueIterator &a, const ValueIterator &b) 00205 { 00206 return !(a == b); 00207 } 00208 00210 inline bool 00211 operator!=(const ValueIterator &a, const ValueIteratorEnd_ &b) 00212 { 00213 return !(a == b); 00214 } 00215 00217 inline bool 00218 operator!=(const ValueIteratorEnd_ &a, const ValueIterator &b) 00219 { 00220 return !(a == b); 00221 } 00222 00224 inline bool 00225 operator!=(const ValueIteratorEnd_ &a, const ValueIteratorEnd_ &b) 00226 { 00227 return !(a == b); 00228 } 00229 00230 } 00231 00232 #endif // XAPIAN_INCLUDED_VALUEITERATOR_H