00001 /* flint_cursor.h: Interface to Btree cursors 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2003,2004,2006,2007,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_FLINT_CURSOR_H 00023 #define OM_HGUARD_FLINT_CURSOR_H 00024 00025 #include <xapian/visibility.h> 00026 00027 #include "flint_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 FlintTable; 00063 00067 class XAPIAN_VISIBILITY_DEFAULT FlintCursor { 00068 private: 00070 FlintCursor(const FlintCursor &); 00071 00073 FlintCursor & operator=(const FlintCursor &); 00074 00079 void rebuild(); 00080 00086 bool is_positioned; 00087 00090 bool is_after_end; 00091 00093 enum { UNREAD, UNCOMPRESSED, COMPRESSED } tag_status; 00094 00096 FlintTable * B; 00097 00099 Cursor_ * C; 00100 00101 unsigned long version; 00102 00104 int level; 00105 00125 void get_key(string * key) const; 00126 00127 public: 00139 FlintCursor(FlintTable *B); 00140 00142 ~FlintCursor(); 00143 00146 string current_key; 00147 00151 string current_tag; 00152 00165 bool read_tag(bool keep_compressed = false); 00166 00181 bool next(); 00182 00188 bool prev(); 00189 00212 bool find_entry(const string &key); 00213 00215 void find_entry_lt(const string &key) { 00216 if (find_entry(key)) prev(); 00217 } 00218 00224 bool find_entry_ge(const string &key); 00225 00228 void to_end() { is_after_end = true; } 00229 00235 bool after_end() const { return is_after_end; } 00236 00242 bool del(); 00243 00245 FlintTable * get_table() const { return B; } 00246 }; 00247 00248 #endif /* OM_HGUARD_FLINT_CURSOR_H */