diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
| commit | 5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch) | |
| tree | 1a81af141708b826e9c61e8a04019994fcca8298 /src/ops/operator.h | |
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/ops/operator.h')
| -rw-r--r-- | src/ops/operator.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/ops/operator.h b/src/ops/operator.h new file mode 100644 index 0000000..d4a7af8 --- /dev/null +++ b/src/ops/operator.h | |||
| @@ -0,0 +1,97 @@ | |||
| 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 OPERATORH | ||
| 21 | #define OPERATORH | ||
| 22 | |||
| 23 | #include <mt/mstring.h> | ||
| 24 | #include <mt/mvec.h> | ||
| 25 | |||
| 26 | const mstring lt_tag="lt"; | ||
| 27 | |||
| 28 | /////////////////////////////////////////////// | ||
| 29 | |||
| 30 | class op_env; | ||
| 31 | struct op_t { | ||
| 32 | typedef void (*op1_t)(mstream&,op_env&,const sref&); | ||
| 33 | typedef void (*op2_t)(mstream&,op_env&,const sref&,const sref&); | ||
| 34 | |||
| 35 | mstring name,desc; | ||
| 36 | int pre1,pre2; | ||
| 37 | int left,right; | ||
| 38 | op1_t f1; op2_t f2; | ||
| 39 | |||
| 40 | op_t(const mstring& s,int p1,int p2,int l,int r,op1_t op1,op2_t op2,const mstring& d): | ||
| 41 | name(s),pre1(p1),pre2(p2),left(l),right(r),f1(op1),f2(op2),desc(d) {} | ||
| 42 | op_t(const mstring& s,int p1,int p2,op1_t op1,op2_t op2,const mstring& d): | ||
| 43 | name(s),pre1(p1),pre2(p2),left(2),right(2),f1(op1),f2(op2),desc(d) {} | ||
| 44 | op_t(const mstring& s,int p,op1_t op,const mstring& d): | ||
| 45 | name(s),pre1(p),pre2(0),left(0),right(2),f1(op),f2(0),desc(d) {} | ||
| 46 | op_t(const mstring& s,int p,op2_t op,const mstring& d): | ||
| 47 | name(s),pre1(0),pre2(p),left(2),right(2),f1(0),f2(op),desc(d) {} | ||
| 48 | }; | ||
| 49 | |||
| 50 | #define OP1_IMPL(n) \ | ||
| 51 | static void impl_##n(mstream& out,op_env& env,const sref& a) | ||
| 52 | #define OP2_IMPL(n) \ | ||
| 53 | static void impl_##n(mstream& out,op_env& env,const sref& L,const sref& R) | ||
| 54 | |||
| 55 | //////////////////////////////////////////////////////////// | ||
| 56 | |||
| 57 | typedef op_t* opmap_t; | ||
| 58 | |||
| 59 | struct opmap : public mrvec<opmap_t> { | ||
| 60 | typedef mrvec<opmap_t>::iterator iterator; | ||
| 61 | typedef mrvec<opmap_t>::const_iterator const_iterator; | ||
| 62 | |||
| 63 | struct comp_t { | ||
| 64 | sref key; | ||
| 65 | comp_t(const sref& skey) : key(skey) {} | ||
| 66 | bool operator()(const op_t* a,const op_t* b) const { | ||
| 67 | return (a?((const sref&)a->name):key)<(b?((const sref&)b->name):key); | ||
| 68 | } | ||
| 69 | }; | ||
| 70 | |||
| 71 | opmap() : mrvec<opmap_t>() {} | ||
| 72 | ~opmap() { clear(); } | ||
| 73 | |||
| 74 | void clear(); // overrides parent | ||
| 75 | void erase(iterator p); // overrides parent | ||
| 76 | |||
| 77 | const op_t* get(const sref& t) const; | ||
| 78 | const op_t* add(op_t* op); | ||
| 79 | }; | ||
| 80 | |||
| 81 | #define OP_ADD(p,f,d) M.add(new op_t(#f,p,impl_##f,d)) | ||
| 82 | #define OP_ADDN(p,f,n,d) M.add(new op_t(#n,p,impl_##f,d)) | ||
| 83 | #define OP_ADD2(p1,p2,f,n,d) M.add(new op_t(#n,p1,p2,impl_##f,impl_##f,d)) | ||
| 84 | |||
| 85 | /////////////////////////////////////////// | ||
| 86 | |||
| 87 | void opAddBasic(opmap& map); | ||
| 88 | void opAddComp(opmap& map); | ||
| 89 | void opAddString(opmap& map); | ||
| 90 | inline void opAddHEXP(opmap& map) { | ||
| 91 | opAddBasic(map); | ||
| 92 | opAddComp(map); | ||
| 93 | opAddString(map); | ||
| 94 | } | ||
| 95 | void opAddLatex(opmap& map); | ||
| 96 | |||
| 97 | #endif | ||
