1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * gdbmclass.h --
|
---|
4 | * Copyright (C) 1999-2008 The New Zealand Digital Library Project
|
---|
5 | *
|
---|
6 | * A component of the Greenstone digital library software
|
---|
7 | * from the New Zealand Digital Library Project at the
|
---|
8 | * University of Waikato, New Zealand.
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *
|
---|
24 | *********************************************************************/
|
---|
25 |
|
---|
26 |
|
---|
27 | #ifndef GDBMCLASS_H
|
---|
28 | #define GDBMCLASS_H
|
---|
29 |
|
---|
30 |
|
---|
31 | #include "gsdlconf.h"
|
---|
32 | #include "text_t.h"
|
---|
33 | #include "infodbclass.h"
|
---|
34 |
|
---|
35 | #ifdef __WIN32__
|
---|
36 |
|
---|
37 | #ifdef __cplusplus
|
---|
38 | extern "C" {
|
---|
39 | #endif
|
---|
40 | #include "autoconf.h"
|
---|
41 | #include "systems.h"
|
---|
42 | #include "gdbmconst.h"
|
---|
43 | #include "gdbm.h"
|
---|
44 | #ifdef __cplusplus
|
---|
45 | }
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #else
|
---|
49 | #include <gdbm.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 | class gdbmclass
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | gdbmclass() {gdbmfile = NULL; logout = &cerr;};
|
---|
57 | ~gdbmclass();
|
---|
58 |
|
---|
59 | // returns true if opened
|
---|
60 | bool opendatabase (const text_t &filename, int mode, int num_retrys,
|
---|
61 | bool need_filelock);
|
---|
62 | void closedatabase ();
|
---|
63 |
|
---|
64 | // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)
|
---|
65 | // it expects child, parent, etc. to exist if syntax has been used
|
---|
66 | // so you should test before using
|
---|
67 | text_t translate_OID (const text_t &OID, infodbclass &info);
|
---|
68 |
|
---|
69 | // returns true on success
|
---|
70 | bool getinfo (const text_t& key, infodbclass &info);
|
---|
71 | void setlogout (ostream *thelogout) {logout = thelogout;}
|
---|
72 |
|
---|
73 | // returns true if exists
|
---|
74 | bool exists (const text_t& key);
|
---|
75 |
|
---|
76 | // returns true on success
|
---|
77 | bool setinfo (const text_t &key, const infodbclass &info);
|
---|
78 | // returns true on success
|
---|
79 | bool setinfo (const text_t &key, const text_t &data);
|
---|
80 |
|
---|
81 | void deletekey (const text_t &key);
|
---|
82 |
|
---|
83 | // getfirstkey and getnextkey are used for traversing the database
|
---|
84 | // no insertions or deletions should be carried out while traversing
|
---|
85 | // the database. when there are no keys left to visit in the database
|
---|
86 | // an empty string is returned.
|
---|
87 | text_t getfirstkey ();
|
---|
88 | text_t getnextkey (const text_t &key);
|
---|
89 |
|
---|
90 | // returns true on success
|
---|
91 | bool getkeydata (const text_t& key, text_t &data);
|
---|
92 |
|
---|
93 | protected:
|
---|
94 | text_t openfile;
|
---|
95 | GDBM_FILE gdbmfile;
|
---|
96 | ostream *logout;
|
---|
97 |
|
---|
98 | void get_first_child (text_t &OID, infodbclass &info);
|
---|
99 | void get_last_child (text_t &OID, infodbclass &info);
|
---|
100 | void get_next_sibling (text_t &OID, infodbclass &info);
|
---|
101 | void get_previous_sibling (text_t &OID, infodbclass &info);
|
---|
102 |
|
---|
103 |
|
---|
104 | // returns true on success
|
---|
105 | bool getinfoline (text_t::iterator &here, text_t::iterator end,
|
---|
106 | text_t &key, text_t &value);
|
---|
107 | };
|
---|
108 |
|
---|
109 |
|
---|
110 | #endif
|
---|