source: trunk/gsdl/src/recpt/infodbclass.h@ 928

Last change on this file since 928 was 928, checked in by kjm18, 24 years ago

search history stuff added.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/**********************************************************************
2 *
3 * infodbclass.h --
4 * Copyright (C) 1999 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 * $Id: infodbclass.h 928 2000-02-15 22:53:52Z kjm18 $
25 *
26 *********************************************************************/
27
28
29#ifndef INFODBCLASS_H
30#define INFODBCLASS_H
31
32
33#include "gsdlconf.h"
34#include "text_t.h"
35
36#ifdef __WIN32__
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41#include "autoconf.h"
42#include "systems.h"
43#include "gdbmconst.h"
44#include "gdbm.h"
45#ifdef __cplusplus
46}
47#endif
48
49#else
50#include <gdbm.h>
51#endif
52
53
54typedef map<text_t, text_tarray, lttext_t> text_tarraymap;
55
56
57// infodbclass is used to store information about a object
58class infodbclass {
59protected:
60 text_tarraymap info;
61
62public:
63 // type support for text_tarraymap
64 typedef text_tarraymap::iterator iterator;
65 typedef text_tarraymap::const_iterator const_iterator;
66 typedef text_tarraymap::reference reference;
67 typedef text_tarraymap::const_reference const_reference;
68 typedef text_tarraymap::size_type size_type;
69 typedef text_tarraymap::difference_type difference_type;
70 typedef text_tarraymap::const_reverse_iterator const_reverse_iterator;
71 typedef text_tarraymap::reverse_iterator reverse_iterator;
72
73 // constructors
74 infodbclass ();
75
76 // basic container support
77 iterator begin () {return info.begin();}
78 const_iterator begin () const {return info.begin();}
79 iterator end () {return info.end();}
80 const_iterator end () const {return info.end();}
81
82 void erase(iterator pos) {info.erase(pos);}
83 void erase(iterator first, iterator last) {info.erase(first, last);}
84 infodbclass &operator=(const infodbclass &x) {info=x.info;return *this;}
85
86 bool empty () const {return info.empty();}
87 size_type size() const {return info.size();}
88
89
90 // added functionality
91 void clear () {info.erase(info.begin(),info.end());}
92
93 // the following functions deal with keys that can only
94 // have one value for compatibility
95
96 // getinfo returns NULL if there isn't an entry with
97 // 'key' already defined, getintinfo returns 0 if there wasn't an
98 // entry with 'key' defined and operator[] returns "" if
99 // 'key' wasn't already defined (and sets 'key'="").
100 void setinfo (const text_t &key, const text_t &value);
101 void setintinfo (const text_t &key, int value);
102 void setcinfo (const text_t &key, unsigned short c);
103 text_t *getinfo (const text_t &key);
104 int getintinfo (const text_t &key);
105 text_t &operator[] (const text_t &key);
106
107
108 // the next set of functions allow you to set and access keys
109 // that can have more than one value
110
111 // getmultinfo returns NULL if there isn't an entry with
112 // 'key' already defined
113 void addinfo (const text_t &key, const text_t &value);
114 void addintinfo (const text_t &key, int value);
115 void addcinfo (const text_t &key, unsigned short c);
116 text_tarray *getmultinfo (const text_t &key);
117};
118
119
120class gdbmclass {
121public:
122 gdbmclass() {gdbmfile = NULL; logout = &cerr;};
123 ~gdbmclass() {};
124
125 // returns true if opened
126 bool opendatabase (const text_t &filename, int mode, int num_retrys,
127 bool need_filelock);
128 void closedatabase ();
129
130 // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)
131 // it expects child, parent, etc. to exist if syntax has been used
132 // so you should test before using
133 text_t translate_OID (const text_t &OID, infodbclass &info);
134
135 // returns true on success
136 bool getinfo (text_t key, infodbclass &info);
137 void setlogout (ostream *thelogout) {logout = thelogout;}
138
139 // returns true if exists
140 bool exists (text_t key);
141
142 // returns true on success
143 bool setinfo (const text_t &key, const infodbclass &info);
144 // returns true on success
145 bool setinfo (const text_t &key, const text_t &data);
146
147 void deletekey (const text_t &key);
148
149 // getfirstkey and getnextkey are used for traversing the database
150 // no insertions or deletions should be carried out while traversing
151 // the database. when there are no keys left to visit in the database
152 // an empty string is returned.
153 text_t getfirstkey ();
154 text_t getnextkey (const text_t &key);
155
156 // returns true on success
157 bool getkeydata (text_t key, text_t &data);
158
159protected:
160 text_t openfile;
161 GDBM_FILE gdbmfile;
162 ostream *logout;
163
164 void get_first_child (text_t &OID, infodbclass &info);
165 void get_last_child (text_t &OID, infodbclass &info);
166 void get_next_sibling (text_t &OID, infodbclass &info);
167 void get_previous_sibling (text_t &OID, infodbclass &info);
168
169
170 // returns true on success
171 bool getinfoline (text_t::iterator &here, text_t::iterator end,
172 text_t &key, text_t &value);
173};
174
175
176#endif
177
178
179
180
181
Note: See TracBrowser for help on using the repository browser.