00001 /* chert_cursor.h: Interface to Btree cursors 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2003,2004,2006,2007,2008,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 OM_HGUARD_CHERT_CURSOR_H 00023 #define OM_HGUARD_CHERT_CURSOR_H 00024 00025 #include <xapian/visibility.h> 00026 00027 #include "chert_types.h" 00028 00029 #include <string> 00030 using std::string; 00031 00032 #define BLK_UNUSED uint4(-1) 00033 00034 class Cursor { 00035 private: 00036 // Prevent copying 00037 Cursor(const Cursor &); 00038 Cursor & operator=(const Cursor &); 00039 00040 public: 00042 Cursor() : p(0), c(-1), n(BLK_UNUSED), rewrite(false) 00043 {} 00044 00046 byte * p; 00048 int c; 00057 uint4 n; 00059 bool rewrite; 00060 }; 00061 00062 class ChertTable; 00063 00067 class XAPIAN_VISIBILITY_DEFAULT ChertCursor { 00068 private: 00070 ChertCursor(const ChertCursor &); 00071 00073 ChertCursor & operator=(const ChertCursor &); 00074 00079 void rebuild(); 00080 00081 protected: 00087 bool is_positioned; 00088 00091 bool is_after_end; 00092 00093 private: 00095 enum { UNREAD, UNCOMPRESSED, COMPRESSED } tag_status; 00096 00097 protected: 00099 const ChertTable * B; 00100 00101 private: 00103 Cursor * C; 00104 00105 unsigned long version; 00106 00108 int level; 00109 00129 void get_key(string * key) const; 00130 00131 public: 00143 ChertCursor(const ChertTable *B); 00144 00146 ~ChertCursor(); 00147 00150 string current_key; 00151 00155 string current_tag; 00156 00169 bool read_tag(bool keep_compressed = false); 00170 00185 bool next(); 00186 00192 bool prev(); 00193 00216 bool find_entry(const string &key); 00217 00219 void find_entry_lt(const string &key) { 00220 if (find_entry(key)) prev(); 00221 } 00222 00228 bool find_entry_ge(const string &key); 00229 00232 void to_end() { is_after_end = true; } 00233 00239 bool after_end() const { return is_after_end; } 00240 00242 const ChertTable * get_table() const { return B; } 00243 }; 00244 00245 class MutableChertCursor : public ChertCursor { 00246 public: 00260 MutableChertCursor(ChertTable *B_) : ChertCursor(B_) { } 00261 00267 bool del(); 00268 }; 00269 00270 #endif /* OM_HGUARD_CHERT_CURSOR_H */