00001 /* brass_cursor.h: Interface to Btree cursors 00002 * 00003 * Copyright 1999,2000,2001 BrightStation PLC 00004 * Copyright 2002,2003,2004,2006,2007,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 OM_HGUARD_BRASS_CURSOR_H 00023 #define OM_HGUARD_BRASS_CURSOR_H 00024 00025 #include <xapian/visibility.h> 00026 00027 #include "brass_types.h" 00028 00029 #include <string> 00030 using std::string; 00031 00032 #define BLK_UNUSED uint4(-1) 00033 00034 namespace Brass { 00035 00036 class Cursor { 00037 private: 00038 // Prevent copying 00039 Cursor(const Cursor &); 00040 Cursor & operator=(const Cursor &); 00041 00042 public: 00044 Cursor() : p(0), c(-1), n(BLK_UNUSED), rewrite(false) 00045 {} 00046 00048 byte * p; 00050 int c; 00059 uint4 n; 00061 bool rewrite; 00062 }; 00063 00064 } 00065 00066 class BrassTable; 00067 00071 class XAPIAN_VISIBILITY_DEFAULT BrassCursor { 00072 private: 00074 BrassCursor(const BrassCursor &); 00075 00077 BrassCursor & operator=(const BrassCursor &); 00078 00083 void rebuild(); 00084 00085 protected: 00091 bool is_positioned; 00092 00095 bool is_after_end; 00096 00097 private: 00099 enum { UNREAD, UNCOMPRESSED, COMPRESSED } tag_status; 00100 00101 protected: 00103 const BrassTable * B; 00104 00105 private: 00107 Brass::Cursor * C; 00108 00109 unsigned long version; 00110 00112 int level; 00113 00133 void get_key(string * key) const; 00134 00135 public: 00147 BrassCursor(const BrassTable *B); 00148 00150 ~BrassCursor(); 00151 00154 string current_key; 00155 00159 string current_tag; 00160 00173 bool read_tag(bool keep_compressed = false); 00174 00189 bool next(); 00190 00196 bool prev(); 00197 00220 bool find_entry(const string &key); 00221 00223 void find_entry_lt(const string &key) { 00224 if (find_entry(key)) prev(); 00225 } 00226 00232 bool find_entry_ge(const string &key); 00233 00236 void to_end() { is_after_end = true; } 00237 00243 bool after_end() const { return is_after_end; } 00244 00246 const BrassTable * get_table() const { return B; } 00247 }; 00248 00249 class MutableBrassCursor : public BrassCursor { 00250 public: 00264 MutableBrassCursor(BrassTable *B_) : BrassCursor(B_) { } 00265 00271 bool del(); 00272 }; 00273 00274 #endif /* OM_HGUARD_BRASS_CURSOR_H */