WordDead.cc

Go to the documentation of this file.
00001 //
00002 // WordDead.cc
00003 //
00004 // Part of the ht://Dig package   <http://www.htdig.org/>
00005 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00006 // For copyright details, see the file COPYING in your distribution
00007 // or the GNU General Public License version 2 or later
00008 // <http://www.gnu.org/copyleft/gpl.html>
00009 //
00010 // $Id: WordDead_8cc-source.html,v 1.1 2008/06/08 10:13:08 sebdiaz Exp $
00011 //
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif /* HAVE_CONFIG_H */
00015 
00016 #include <fcntl.h>
00017 
00018 #include "WordDead.h"
00019 #include "WordListOne.h"
00020 
00021 class WordDeadCursor {
00022 public:
00023   WordDBCursor* cursor;
00024 };
00025 
00026 WordDead::~WordDead()
00027 {
00028   delete db;
00029   delete mask;
00030 }
00031 
00032 int WordDead::Initialize(WordList* nwords)
00033 {
00034   words = nwords;
00035   db = new WordDB(nwords->GetContext()->GetDBInfo());
00036   mask = new WordKey(words->GetContext());
00037   return OK;
00038 }
00039 
00040 int WordDead::Open()
00041 {
00042   const String& filename = words->Filename();
00043   int flags = words->Flags();
00044 
00045   db->set_pagesize(words->Pagesize());
00046 
00047   return db->Open(filename, "dead", DB_BTREE, flags, 0666, WORD_DB_DEAD) == 0 ? OK : NOTOK;
00048 }
00049 
00050 int WordDead::Remove()
00051 {
00052   return db->Remove(words->Filename(), "dead") == 0 ? OK : NOTOK;
00053 }
00054 
00055 int WordDead::Close()
00056 {
00057   return db->Close() == 0 ? OK : NOTOK;
00058 }
00059 
00060 int WordDead::Normalize(WordKey& key) const
00061 {
00062   int nfields = words->GetContext()->GetKeyInfo().nfields;
00063   int i;
00064   //
00065   // Undefine in 'key' all fields not defined in 'mask'
00066   //
00067   for(i = 0; i < nfields; i++) {
00068     if(!mask->IsDefined(i))
00069       key.Set(i, WORD_KEY_VALUE_INVALID);
00070   }
00071 
00072   return OK;
00073 }
00074 
00075 int WordDead::Exists(const WordKey& key) const
00076 {
00077   WordKey tmp_key = key;
00078 
00079   Normalize(tmp_key);
00080 
00081   String coded;
00082   String dummy;
00083 
00084   tmp_key.Pack(coded);
00085 
00086   return db->Get(0, coded, dummy, 0) == 0;
00087 }
00088 
00089 int WordDead::Put(const WordKey& key) const
00090 {
00091   WordKey tmp_key = key;
00092 
00093   Normalize(tmp_key);
00094 
00095   String coded;
00096   String dummy;
00097 
00098   tmp_key.Pack(coded);
00099 
00100   return db->Put(0, coded, dummy, 0) == 0 ? OK : NOTOK;
00101 }
00102 
00103 WordDeadCursor* WordDead::Cursor() const
00104 {
00105   WordDeadCursor* cursor = new WordDeadCursor;
00106   cursor->cursor = db->Cursor();
00107 
00108   return cursor;
00109 }
00110 
00111 int WordDead::Next(WordDeadCursor* cursor, WordKey& key)
00112 {
00113   String coded;
00114   String dummy;
00115   int ret = cursor->cursor->Get(coded, dummy, DB_NEXT);
00116   if(ret != 0) {
00117     delete cursor->cursor;
00118     delete cursor;
00119   } else {
00120     key.Unpack(coded);
00121   }
00122   return ret;
00123 }

Generated on Sun Jun 8 10:56:40 2008 for GNUmifluz by  doxygen 1.5.5