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

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.7     ! paf         6:        $Id: int.C,v 1.6 2001/03/11 08:28:40 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"
                     13: 
                     14: // global var
                     15: 
                     16: VClass *int_class;
                     17: 
                     18: // methods
                     19: 
                     20: static void _int(Request& r, Array *) {
                     21:        Pool& pool=r.pool();
                     22:        VInt *vint=static_cast<VInt *>(r.self);
                     23:        Value& value=*new(pool) VInt(pool, vint->get_int());
1.3       paf        24:        r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1       paf        25: }
                     26: 
                     27: static void _double(Request& r, Array *) {
                     28:        Pool& pool=r.pool();
                     29:        VInt *vint=static_cast<VInt *>(r.self);
                     30:        Value& value=*new(pool) VDouble(pool, vint->get_double());
1.3       paf        31:        r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1       paf        32: }
                     33: 
                     34: static void _inc(Request& r, Array *params) {
                     35:        VInt *vint=static_cast<VInt *>(r.self);
                     36:        int increment=params->size()?
1.6       paf        37:                static_cast<int>(r.autocalc(
                     38:                        *static_cast<Value *>(params->get(0)),
                     39:                        0/*no name*/,
                     40:                        false/*don't make it string*/).get_double()):1;
1.1       paf        41:        vint->inc(increment);
                     42: }
                     43: 
1.2       paf        44: void initialize_int_class(Pool& pool, VClass& vclass) {
1.7     ! paf        45:        vclass.add_native_method("int", _int, 0, 0); // ^int.int[]
        !            46:        vclass.add_native_method("double", _double, 0, 0); // ^int.double[]
        !            47:        vclass.add_native_method("inc", _inc, 0, 1); // ^int.inc[] ^int.inc[offset]
1.1       paf        48: }

E-mail: