diff options
Diffstat (limited to 'src/hdb/comp.cc')
| -rw-r--r-- | src/hdb/comp.cc | 78 |
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> | ||
| 21 | using namespace std; | ||
| 22 | |||
| 23 | const mstring compat="(compatibility)"; | ||
| 24 | const int zkey=0; | ||
| 25 | |||
| 26 | OP2_IMPL(lti) {out<<(atoi(L)<atoi(R));} | ||
| 27 | OP2_IMPL(lei) {out<<(atoi(L)<=atoi(R));} | ||
| 28 | OP2_IMPL(gei) {out<<(atoi(L)>=atoi(R));} | ||
| 29 | OP2_IMPL(gti) {out<<(atoi(L)>atoi(R));} | ||
| 30 | |||
| 31 | void 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 | |||
| 48 | const 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 | |||
| 58 | void 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 | |||
| 67 | void 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 | |||
