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

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

Moved from src/colservr and added capability to write out data.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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 368 1999-07-11 08:27:52Z 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 true if opened
86 bool opendatabase (const text_t &filename, int mode=GDBM_READER, int num_retrys=1);
87 void closedatabase ();
88
89 // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)
90 // it expects child, parent, etc. to exist if syntax has been used
91 // so you should test before using
92 text_t translate_OID (const text_t &OID, infodbclass &info);
93
94 // returns true on success
95 bool getinfo (text_t key, infodbclass &info);
96 void setlogout (ostream *thelogout) {logout = thelogout;}
97
98 // returns true if exists
99 bool exists (text_t key);
100
101 // returns true on success
102 bool setinfo (const text_t &key, const infodbclass &info);
103
104protected:
105 text_t openfile;
106 GDBM_FILE gdbmfile;
107 ostream *logout;
108
109 void get_first_child (text_t &OID, infodbclass &info);
110 void get_last_child (text_t &OID, infodbclass &info);
111 void get_next_sibling (text_t &OID, infodbclass &info);
112 void get_previous_sibling (text_t &OID, infodbclass &info);
113
114 // returns true on success
115 bool getkeydata (text_t key, text_t &data);
116
117 // returns true on success
118 bool getinfoline (text_t::iterator &here, text_t::iterator end,
119 text_t &key, text_t &value);
120};
121
122
123#endif
Note: See TracBrowser for help on using the repository browser.