source: branches/New_Config_Format-branch/gsdl/src/recpt/infodbclass.h@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

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