Annotation of parser3/src/classes/int.C, revision 1.15

1.1       paf         1: /*
1.4       paf         2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.5       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.4       paf         5: 
1.15    ! paf         6:        $Id: int.C,v 1.14 2001/03/13 13:43:28 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #include "pa_request.h"
                     10: #include "_int.h"
                     11: #include "pa_vdouble.h"
                     12: #include "pa_vint.h"
1.12      paf        13: #include "_string.h"
1.1       paf        14: 
                     15: // global var
                     16: 
1.14      paf        17: VStateless_class *int_class;
1.1       paf        18: 
                     19: // methods
                     20: 
1.10      paf        21: static void _int(Request& r, const String&, Array *) {
1.1       paf        22:        Pool& pool=r.pool();
                     23:        VInt *vint=static_cast<VInt *>(r.self);
                     24:        Value& value=*new(pool) VInt(pool, vint->get_int());
1.15    ! paf        25:        r.write_no_lang(value);
1.1       paf        26: }
                     27: 
1.10      paf        28: static void _double(Request& r, const String&, Array *) {
1.1       paf        29:        Pool& pool=r.pool();
                     30:        VInt *vint=static_cast<VInt *>(r.self);
                     31:        Value& value=*new(pool) VDouble(pool, vint->get_double());
1.15    ! paf        32:        r.write_no_lang(value);
1.1       paf        33: }
                     34: 
1.13      paf        35: typedef void (*vint_op_func_ptr)(VInt& vint, double param);
                     36: 
                     37: static void __inc(VInt& vint, double param) { vint.inc((int)param); }
                     38: static void __dec(VInt& vint, double param) { vint.inc((int)-param); }
                     39: static void __mul(VInt& vint, double param) { vint.mul(param); }
                     40: static void __div(VInt& vint, double param) { vint.div(param); }
                     41: static void __mod(VInt& vint, double param) { vint.mod((int)param); }
                     42: 
                     43: static void vint_op(Request& r, Array *params, 
                     44:                                         vint_op_func_ptr func) {
1.1       paf        45:        VInt *vint=static_cast<VInt *>(r.self);
1.13      paf        46:        double param=params->size()?
                     47:                r.process(
1.6       paf        48:                        *static_cast<Value *>(params->get(0)),
                     49:                        0/*no name*/,
1.11      paf        50:                        false/*don't intercept string*/).get_double():1;
1.13      paf        51:        (*func)(*vint, param);
1.1       paf        52: }
                     53: 
1.13      paf        54: static void _inc(Request& r, const String&, Array *params) { vint_op(r, params, &__inc); }
                     55: static void _dec(Request& r, const String&, Array *params) { vint_op(r, params, &__dec); }
                     56: static void _mul(Request& r, const String&, Array *params) { vint_op(r, params, &__mul); }
                     57: static void _div(Request& r, const String&, Array *params) { vint_op(r, params, &__div); }
                     58: static void _mod(Request& r, const String&, Array *params) { vint_op(r, params, &__mod); }
1.15    ! paf        59: 
        !            60: // initialize
1.13      paf        61: 
1.14      paf        62: void initialize_int_class(Pool& pool, VStateless_class& vclass) {
1.9       paf        63:        // ^int.int[]
                     64:        vclass.add_native_method("int", _int, 0, 0);
                     65: 
                     66:        // ^int.double[]
                     67:        vclass.add_native_method("double", _double, 0, 0);
                     68: 
                     69:        // ^int.inc[] 
                     70:        // ^int.inc[offset]
                     71:        vclass.add_native_method("inc", _inc, 0, 1);
1.13      paf        72:        // ^int.dec[] 
                     73:        // ^int.dec[offset]
                     74:        vclass.add_native_method("dec", _dec, 0, 1);
                     75:        // ^int.mul[k] 
                     76:        vclass.add_native_method("mul", _mul, 1, 1);
                     77:        // ^int.div[d]
                     78:        vclass.add_native_method("div", _div, 1, 1);
                     79:        // ^int.mod[offset]
                     80:        vclass.add_native_method("mod", _mod, 1, 1);
                     81: 
1.12      paf        82: 
                     83:        // ^int.format[]
                     84:        vclass.add_native_method("format", _string_format, 1, 1);
1.1       paf        85: }

E-mail: