Annotation of parser3/src/classes/int.C, revision 1.14
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.14 ! paf 6: $Id: int.C,v 1.13.2.1 2001/03/13 13:39:55 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.3 paf 25: r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
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.3 paf 32: r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
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); }
59:
1.14 ! paf 60: void initialize_int_class(Pool& pool, VStateless_class& vclass) {
1.9 paf 61: // ^int.int[]
62: vclass.add_native_method("int", _int, 0, 0);
63:
64: // ^int.double[]
65: vclass.add_native_method("double", _double, 0, 0);
66:
67: // ^int.inc[]
68: // ^int.inc[offset]
69: vclass.add_native_method("inc", _inc, 0, 1);
1.13 paf 70: // ^int.dec[]
71: // ^int.dec[offset]
72: vclass.add_native_method("dec", _dec, 0, 1);
73: // ^int.mul[k]
74: vclass.add_native_method("mul", _mul, 1, 1);
75: // ^int.div[d]
76: vclass.add_native_method("div", _div, 1, 1);
77: // ^int.mod[offset]
78: vclass.add_native_method("mod", _mod, 1, 1);
79:
1.12 paf 80:
81: // ^int.format[]
82: vclass.add_native_method("format", _string_format, 1, 1);
1.1 paf 83: }
E-mail: