1 ///###////////////////////////////////////////////////////////////////////////
2 //
3 // Burton Computer Corporation
4 // http://www.burton-computer.com
5 // http://www.cooldevtools.com
6 // $Id: FrequencyDBImpl_dbm.h 272 2007-01-06 19:37:27Z brian $
7 //
8 // Copyright (C) 2007 Burton Computer Corporation
9 // ALL RIGHTS RESERVED
10 //
11 // This program is open source software; you can redistribute it
12 // and/or modify it under the terms of the Q Public License (QPL)
13 // version 1.0. Use of this software in whole or in part, including
14 // linking it (modified or unmodified) into other programs is
15 // subject to the terms of the QPL.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // Q Public License for more details.
21 //
22 // You should have received a copy of the Q Public License
23 // along with this program; see the file LICENSE.txt.  If not, visit
24 // the Burton Computer Corporation or CoolDevTools web site
25 // QPL pages at:
26 //
27 //    http://www.burton-computer.com/qpl.html
28 //    http://www.cooldevtools.com/qpl.html
29 //
30 
31 #ifndef _FrequencyDBImpl_dbm_h
32 #define _FrequencyDBImpl_dbm_h
33 
34 #ifdef USE_DBM
35 
36 extern "C" {
37 #include <ndbm.h>
38 }
39 
40 #include "FrequencyDBImpl.h"
41 
42 class LockFile;
43 
44 class FrequencyDBImpl_dbm : public FrequencyDBImpl
45 {
46 public:
47   FrequencyDBImpl_dbm();
48   ~FrequencyDBImpl_dbm();
49 
50   bool open(const string &filename,
51             bool read_only,
52             int create_mode);
53   void close();
54 
55   void flush();
56 
57   void writeWord(const string &word,
58                  const WordData &word_data);
59 
60   bool readWord(const string &word,
61                 WordData &word_data);
62 
63   bool firstWord(string &word,
64                  WordData &counts);
65 
66   bool nextWord(string &word,
67                 WordData &counts);
68 
69   string getDatabaseType() const;
70 
71   void sweepOutOldTerms(const CleanupManager &cleanman);
72 
73   static FrequencyDBImpl *factory(const DatabaseConfig *);
74 
75 private:
76   bool loadKey(const datum &key,
77                string &word,
78                WordData &counts) const;
79 
80   bool loadKey(const datum &key,
81                WordData &counts) const;
82 
83 private:
84   /// Not implemented.
85   FrequencyDBImpl_dbm(const FrequencyDBImpl_dbm &);
86 
87   /// Not implemented.
88   FrequencyDBImpl_dbm& operator=(const FrequencyDBImpl_dbm &);
89 
90 private:
91   DBM *m_file;
92 };
93 
94 #endif // USE_DBM
95 
96 #endif // _FrequencyDBImpl_dbm_h
97