summaryrefslogtreecommitdiff
path: root/src/hdb/db.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hdb/db.h')
-rw-r--r--src/hdb/db.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/hdb/db.h b/src/hdb/db.h
new file mode 100644
index 0000000..6621944
--- /dev/null
+++ b/src/hdb/db.h
@@ -0,0 +1,129 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef DBH
21#define DBH
22
23#include <hdb/sortable.h>
24#include <mt/msmap.h>
25
26////////////////////////////////////////////////////
27//
28// OK for MT and MP
29//
30
31class dbmap {
32public:
33 dbmap();
34 ~dbmap();
35
36 filemap::head_t* head() { return file->head(); }
37 const filemap::head_t* head() const { return file->head(); }
38
39 int remap();
40
41 int size() const { return recs.size(); }
42 int empty() const { return recs.empty(); }
43
44 const sref operator()(int row,int col) const throw(merror_t) {
45 check(); return recs[row].rec->at(col);
46 }
47 const sref at(int row,int col) const throw(merror_t) {
48 check(); return recs[row].rec->at(col);
49 }
50
51 ///////////////////////////////////////////////////////
52
53 void Get(int row,spile& list) throw(merror_t);
54 void Set(int row,int col,const sref& s) throw(merror_t);
55 void Set(int row,const spile& list) throw(merror_t);
56
57 ///////////////////////////////////////////////////////
58
59 void Rem(int row) throw(merror_t);
60 int Insert(const spile& list,int unique) throw(merror_t);
61
62 ///////////////////////////////////////////////////////
63
64 int Tables() const { return head()->tables.get(); }
65 const sref Table(int col) const { check(); return head()->get(col); }
66
67 ///////////////////////////////////////////////////////
68
69 void SetTable(int col,const sref& name) throw(merror_t);
70 void RemTable(int col) throw(merror_t);
71 void InsertTable(int col,const sref& name) throw(merror_t);
72
73 ///////////////////////////////////////////////////////
74
75 int Index() const { return index; }
76 int FindIndex(const sref& tab) const { return tmap.get(tab); }
77 int Index(const sref& tab) const throw(merror_t) {
78 int p=FindIndex(tab);
79 if(p<0) THROW("db: table ["<<tab<<"] does not exist");
80 return p;
81 }
82
83 ///////////////////////////////////////////////////////
84
85 const mstring& Compname() const { return compname; }
86
87 void Sort(const sref& tab,const sref& cmp) throw(merror_t);
88 void Order(const sref& tab,const sref& cmp) throw(merror_t);
89
90 int Find(const sref& key) const { return recs.get(key); }
91
92 ///////////////////////////////////////////////////////
93
94 void Open(const mstring& path,int update=0,int prot=0600) throw(merror_t);
95 void Saveas(const mstring& path,int prot=0600) throw(merror_t);
96 time_t Lastmod() const { return file->Lastmod(); }
97 void Close();
98
99 static void Sync();
100
101protected:
102 dbmap(const dbmap& db) {}
103 void operator=(const dbmap& db) {}
104
105 void check() const {
106 if(fatal!=head()->fatal.get()) THROW("db: fatal state change")
107 }
108
109 void remap_recs();
110 void remap_tabs();
111
112 static void setup();
113 static const op_t* CompOperator(const sref& s);
114
115 static filemap* flist;
116 static mutex_t mutex;
117 static opmap M;
118private:
119 int wok,minor,major,fatal,index;
120 mstring compname;
121 filemap* file;
122 rimap tmap;
123 indexmap recs;
124};
125
126void Convert(dbmap& db,const char* path);
127
128#endif
129