source: main/tags/2.80/gsdl/src/recpt/infodbclass.h@ 24528

Last change on this file since 24528 was 7434, checked in by mdewsnip, 20 years ago

(Human Info) Initial support for retrieving language specific information.

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