1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * dbclass.h --
|
---|
4 | * Copyright (C) 1999-2008 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 | #ifndef DBCLASS_H
|
---|
27 | #define DBCLASS_H
|
---|
28 |
|
---|
29 |
|
---|
30 | #include "text_t.h"
|
---|
31 | #include "infodbclass.h"
|
---|
32 |
|
---|
33 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
34 | # include <ospace\std\iostream>
|
---|
35 | # include <ospace\std\fstream>
|
---|
36 | #elif defined(GSDL_USE_IOS_H)
|
---|
37 | # include <iostream.h>
|
---|
38 | # include <fstream.h>
|
---|
39 | #else
|
---|
40 | # include <iostream>
|
---|
41 | # include <fstream>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 |
|
---|
45 | #define DB_READER 1
|
---|
46 | #define DB_WRITER 2
|
---|
47 | #define DB_WRITER_CREATE 3
|
---|
48 |
|
---|
49 |
|
---|
50 | class dbclass
|
---|
51 | {
|
---|
52 | public:
|
---|
53 | dbclass(const text_t& gsdlhome) { logout = &cerr; }
|
---|
54 | virtual ~dbclass();
|
---|
55 |
|
---|
56 | void setlogout (ostream *logout_arg) { logout = logout_arg; }
|
---|
57 |
|
---|
58 |
|
---|
59 | // -----------------------------------------------------------------------------------------------
|
---|
60 | // These functions MUST be implemented by subclasses, as they are database-specific
|
---|
61 |
|
---|
62 | // returns true if opened
|
---|
63 | virtual bool opendatabase (const text_t &filename, int mode, int num_retrys, bool need_filelock) = 0;
|
---|
64 |
|
---|
65 | virtual void closedatabase () = 0;
|
---|
66 |
|
---|
67 | virtual void deletekey (const text_t &key) = 0;
|
---|
68 |
|
---|
69 | // returns file extension string
|
---|
70 | virtual text_t getfileextension () = 0;
|
---|
71 |
|
---|
72 | // returns true on success
|
---|
73 | virtual bool getkeydata (const text_t& key, text_t &data) = 0;
|
---|
74 |
|
---|
75 | // returns array of keys
|
---|
76 | virtual text_tarray getkeys () = 0;
|
---|
77 |
|
---|
78 | // returns true on success
|
---|
79 | virtual bool setkeydata (const text_t &key, const text_t &data) = 0;
|
---|
80 |
|
---|
81 |
|
---|
82 | // -----------------------------------------------------------------------------------------------
|
---|
83 | // These functions may be overwritten by subclasses, but a default implementation is provided
|
---|
84 |
|
---|
85 | // returns true if exists
|
---|
86 | virtual bool exists (const text_t& key);
|
---|
87 |
|
---|
88 | // returns true on success
|
---|
89 | virtual bool getinfo (const text_t& key, infodbclass &info);
|
---|
90 |
|
---|
91 | // returns true on success
|
---|
92 | virtual bool setinfo (const text_t &key, const infodbclass &info);
|
---|
93 |
|
---|
94 |
|
---|
95 | // replaces the .c, .p, .n, .l syntax (child, parent, next, previous)
|
---|
96 | // it expects child, parent, etc. to exist if syntax has been used
|
---|
97 | // so you should test before using
|
---|
98 | text_t translate_OID(const text_t &OID, infodbclass &info);
|
---|
99 |
|
---|
100 | protected:
|
---|
101 | ostream *logout;
|
---|
102 |
|
---|
103 | // returns true on success
|
---|
104 | bool getinfoline (text_t::iterator &here, text_t::iterator end, text_t &key, text_t &value);
|
---|
105 |
|
---|
106 | void get_first_child (text_t &OID, infodbclass &info);
|
---|
107 | void get_last_child (text_t &OID, infodbclass &info);
|
---|
108 | void get_next_sibling (text_t &OID, infodbclass &info);
|
---|
109 | void get_previous_sibling (text_t &OID, infodbclass &info);
|
---|
110 | };
|
---|
111 |
|
---|
112 |
|
---|
113 | #endif
|
---|