From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/ops/operator.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/ops/operator.h (limited to 'src/ops/operator.h') 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 @@ +/************************************************************************* + * + * HTCd - Copyright (C) 1998-2006 Henrik Rydberg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef OPERATORH +#define OPERATORH + +#include +#include + +const mstring lt_tag="lt"; + +/////////////////////////////////////////////// + +class op_env; +struct op_t { + typedef void (*op1_t)(mstream&,op_env&,const sref&); + typedef void (*op2_t)(mstream&,op_env&,const sref&,const sref&); + + mstring name,desc; + int pre1,pre2; + int left,right; + op1_t f1; op2_t f2; + + op_t(const mstring& s,int p1,int p2,int l,int r,op1_t op1,op2_t op2,const mstring& d): + name(s),pre1(p1),pre2(p2),left(l),right(r),f1(op1),f2(op2),desc(d) {} + op_t(const mstring& s,int p1,int p2,op1_t op1,op2_t op2,const mstring& d): + name(s),pre1(p1),pre2(p2),left(2),right(2),f1(op1),f2(op2),desc(d) {} + op_t(const mstring& s,int p,op1_t op,const mstring& d): + name(s),pre1(p),pre2(0),left(0),right(2),f1(op),f2(0),desc(d) {} + op_t(const mstring& s,int p,op2_t op,const mstring& d): + name(s),pre1(0),pre2(p),left(2),right(2),f1(0),f2(op),desc(d) {} +}; + +#define OP1_IMPL(n) \ +static void impl_##n(mstream& out,op_env& env,const sref& a) +#define OP2_IMPL(n) \ +static void impl_##n(mstream& out,op_env& env,const sref& L,const sref& R) + +//////////////////////////////////////////////////////////// + +typedef op_t* opmap_t; + +struct opmap : public mrvec { + typedef mrvec::iterator iterator; + typedef mrvec::const_iterator const_iterator; + + struct comp_t { + sref key; + comp_t(const sref& skey) : key(skey) {} + bool operator()(const op_t* a,const op_t* b) const { + return (a?((const sref&)a->name):key)<(b?((const sref&)b->name):key); + } + }; + + opmap() : mrvec() {} + ~opmap() { clear(); } + + void clear(); // overrides parent + void erase(iterator p); // overrides parent + + const op_t* get(const sref& t) const; + const op_t* add(op_t* op); +}; + +#define OP_ADD(p,f,d) M.add(new op_t(#f,p,impl_##f,d)) +#define OP_ADDN(p,f,n,d) M.add(new op_t(#n,p,impl_##f,d)) +#define OP_ADD2(p1,p2,f,n,d) M.add(new op_t(#n,p1,p2,impl_##f,impl_##f,d)) + +/////////////////////////////////////////// + +void opAddBasic(opmap& map); +void opAddComp(opmap& map); +void opAddString(opmap& map); +inline void opAddHEXP(opmap& map) { + opAddBasic(map); + opAddComp(map); + opAddString(map); +} +void opAddLatex(opmap& map); + +#endif -- cgit v1.2.3