source: trunk/gsdl/src/colservr/infodbclass.h@ 216

Last change on this file since 216 was 216, checked in by rjmcnab, 25 years ago

Initial revision.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/**********************************************************************
2 *
3 * infodbclass.h --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: infodbclass.h 216 1999-03-30 05:10:07Z rjmcnab $
9 *
10 *********************************************************************/
11
12
13#ifndef INFODBCLASS_H
14#define INFODBCLASS_H
15
16
17#include "gsdlconf.h"
18#include "text_t.h"
19
20#ifdef __WIN32__
21#include "autoconf.h"
22#include "systems.h"
23#include "gdbmconst.h"
24#include "gdbm.h"
25
26#else
27#include <gdbm.h>
28#endif
29
30
31// infodbclass is used to store information about a object
32class infodbclass {
33protected:
34 text_tmap info;
35
36public:
37 //type support for text_tmap
38 typedef text_tmap::iterator iterator;
39 typedef text_tmap::const_iterator const_iterator;
40 typedef text_tmap::reference reference;
41 typedef text_tmap::const_reference const_reference;
42 typedef text_tmap::size_type size_type;
43 typedef text_tmap::difference_type difference_type;
44 typedef text_tmap::const_reverse_iterator const_reverse_iterator;
45 typedef text_tmap::reverse_iterator reverse_iterator;
46
47 // constructors
48 infodbclass ();
49
50 // basic container support
51 iterator begin () {return info.begin();}
52 const_iterator begin () const {return info.begin();}
53 iterator end () {return info.end();}
54 const_iterator end () const {return info.end();}
55
56 void erase(iterator pos) {info.erase(pos);}
57 void erase(iterator first, iterator last) {info.erase(first, last);}
58 infodbclass &operator=(const infodbclass &x) {info=x.info;return *this;}
59
60 bool empty () const {return info.empty();}
61 size_type size() const {return info.size();}
62
63
64 // added functionality
65 void clear () {info.erase(info.begin(),info.end());}
66
67 // getinfo returns NULL if there isn't an entry with
68 // 'key' already defined, getintinfo returns 0 if there wasn't an
69 // entry with 'key' defined and operator[] returns "" if
70 // 'key' wasn't already defined (and sets 'key'="").
71 void setinfo (const text_t &key, const text_t &value);
72 void setintinfo (const text_t &key, int value);
73 void setcinfo (const text_t &key, unsigned short c);
74 text_t *getinfo (const text_t &key);
75 int getintinfo (const text_t &key);
76 text_t &operator[] (const text_t &key) {return info[key];}
77};
78
79
80class gdbmclass {
81public:
82 gdbmclass() {gdbmfile = NULL; logout = &cerr;};
83 ~gdbmclass() {};
84
85 // returns 0 if failed, 1 if opened
86 int opendatabase (const text_t &filename);
87 void closedatabase ();
88
89 // returns 0 on success, -1 on failure
90 int getinfo (text_t key, infodbclass &info);
91 void setlogout (ostream *thelogout) {logout = thelogout;}
92 int exists (text_t key);
93
94protected:
95 text_t openfile;
96 GDBM_FILE gdbmfile;
97 ostream *logout;
98
99 int getkeydata (text_t key, text_t &data);
100 int getinfoline (text_t::iterator &here, text_t::iterator end,
101 text_t &key, text_t &value);
102};
103
104
105#endif
Note: See TracBrowser for help on using the repository browser.