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

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

E-mail: