summaryrefslogtreecommitdiff
path: root/src/hdb/comp.cc
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/hdb/comp.cc
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/hdb/comp.cc')
-rw-r--r--src/hdb/comp.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/hdb/comp.cc b/src/hdb/comp.cc
new file mode 100644
index 0000000..3cb304a
--- /dev/null
+++ b/src/hdb/comp.cc
@@ -0,0 +1,78 @@
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#include <hdb/db.h>
21using namespace std;
22
23const mstring compat="(compatibility)";
24const int zkey=0;
25
26OP2_IMPL(lti) {out<<(atoi(L)<atoi(R));}
27OP2_IMPL(lei) {out<<(atoi(L)<=atoi(R));}
28OP2_IMPL(gei) {out<<(atoi(L)>=atoi(R));}
29OP2_IMPL(gti) {out<<(atoi(L)>atoi(R));}
30
31void dbmap::setup()
32{
33 MLOCK(mutex);
34 if(M.empty()) {
35 opAddComp(M);
36 OP_ADDN(20,lti,lt.int,compat);
37 OP_ADDN(20,lei,le.int,compat);
38 OP_ADDN(20,gei,ge.int,compat);
39 OP_ADDN(20,gti,gt.int,compat);
40
41 M.add(new op_t("lt.case",20,M.get(sref("lt"))->f2,compat));
42 M.add(new op_t("gt.case",20,M.get(sref("gt"))->f2,compat));
43 M.add(new op_t("lt.nocase",20,M.get(sref("ltn"))->f2,compat));
44 M.add(new op_t("gt.nocase",20,M.get(sref("gtn"))->f2,compat));
45 }
46}
47
48const op_t* dbmap::CompOperator(const sref& s)
49{
50 if(M.empty()) setup();
51 const op_t* p=M.get(s);
52 if(!p) THROW("dbmap: could not find operator "<<s);
53 return p;
54}
55
56///////////////////////////////////////////////////////////////////
57
58void dbmap::Sort(const sref& tab,const sref& cmp) throw(merror_t)
59{
60 check();
61 int DO=0;
62 if(cmp.nempty()&&cmp!=compname) { compname=cmp; DO=1; }
63 if(tab.nempty()) { int col=Index(tab); if(col!=index) { index=col; DO=1; } }
64 if(DO) remap_recs();
65}
66
67void dbmap::Order(const sref& tab,const sref& cmp) throw(merror_t)
68{
69 check();
70 if(!wok) THROW("db: cannot order - readonly");
71 Sort(tab,cmp);
72 {
73 HEADLOCK(file);
74 file->head()->setcomp(index,compname);
75 remap_tabs();
76 }
77}
78