Annotation of parser3/src/classes/int.C, revision 1.19
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 ! paf 8: $Id: int.C,v 1.18 2001/04/03 08:23:06 paf Exp $
1.1 paf 9: */
10:
11: #include "pa_request.h"
12: #include "_int.h"
13: #include "pa_vdouble.h"
14: #include "pa_vint.h"
1.12 paf 15: #include "_string.h"
1.1 paf 16:
17: // global var
18:
1.14 paf 19: VStateless_class *int_class;
1.1 paf 20:
21: // methods
22:
1.19 ! paf 23: static void _int(Request& r, const String&, MethodParams *) {
1.1 paf 24: Pool& pool=r.pool();
25: VInt *vint=static_cast<VInt *>(r.self);
26: Value& value=*new(pool) VInt(pool, vint->get_int());
1.15 paf 27: r.write_no_lang(value);
1.1 paf 28: }
29:
1.19 ! paf 30: static void _double(Request& r, const String&, MethodParams *) {
1.1 paf 31: Pool& pool=r.pool();
32: VInt *vint=static_cast<VInt *>(r.self);
1.16 paf 33: Value& value=*new(pool) VDouble(pool, vint->as_double());
1.15 paf 34: r.write_no_lang(value);
1.1 paf 35: }
36:
1.13 paf 37: typedef void (*vint_op_func_ptr)(VInt& vint, double param);
38:
39: static void __inc(VInt& vint, double param) { vint.inc((int)param); }
40: static void __dec(VInt& vint, double param) { vint.inc((int)-param); }
41: static void __mul(VInt& vint, double param) { vint.mul(param); }
42: static void __div(VInt& vint, double param) { vint.div(param); }
43: static void __mod(VInt& vint, double param) { vint.mod((int)param); }
44:
1.19 ! paf 45: static void vint_op(Request& r, MethodParams *params,
1.13 paf 46: vint_op_func_ptr func) {
1.1 paf 47: VInt *vint=static_cast<VInt *>(r.self);
1.13 paf 48: double param=params->size()?
49: r.process(
1.19 ! paf 50: params->get(0),
1.6 paf 51: 0/*no name*/,
1.16 paf 52: false/*don't intercept string*/).as_double():1;
1.13 paf 53: (*func)(*vint, param);
1.1 paf 54: }
55:
1.19 ! paf 56: static void _inc(Request& r, const String&, MethodParams *params) { vint_op(r, params, &__inc); }
! 57: static void _dec(Request& r, const String&, MethodParams *params) { vint_op(r, params, &__dec); }
! 58: static void _mul(Request& r, const String&, MethodParams *params) { vint_op(r, params, &__mul); }
! 59: static void _div(Request& r, const String&, MethodParams *params) { vint_op(r, params, &__div); }
! 60: static void _mod(Request& r, const String&, MethodParams *params) { vint_op(r, params, &__mod); }
1.15 paf 61:
62: // initialize
1.13 paf 63:
1.14 paf 64: void initialize_int_class(Pool& pool, VStateless_class& vclass) {
1.9 paf 65: // ^int.int[]
1.17 paf 66: vclass.add_native_method("int", Method::CT_DYNAMIC, _int, 0, 0);
1.9 paf 67:
68: // ^int.double[]
1.17 paf 69: vclass.add_native_method("double", Method::CT_DYNAMIC, _double, 0, 0);
1.9 paf 70:
71: // ^int.inc[]
72: // ^int.inc[offset]
1.17 paf 73: vclass.add_native_method("inc", Method::CT_DYNAMIC, _inc, 0, 1);
1.13 paf 74: // ^int.dec[]
75: // ^int.dec[offset]
1.17 paf 76: vclass.add_native_method("dec", Method::CT_DYNAMIC, _dec, 0, 1);
1.13 paf 77: // ^int.mul[k]
1.17 paf 78: vclass.add_native_method("mul", Method::CT_DYNAMIC, _mul, 1, 1);
1.13 paf 79: // ^int.div[d]
1.17 paf 80: vclass.add_native_method("div", Method::CT_DYNAMIC, _div, 1, 1);
1.13 paf 81: // ^int.mod[offset]
1.17 paf 82: vclass.add_native_method("mod", Method::CT_DYNAMIC, _mod, 1, 1);
1.13 paf 83:
1.12 paf 84:
1.18 paf 85: // ^int.format{format}
1.17 paf 86: vclass.add_native_method("format", Method::CT_DYNAMIC, _string_format, 1, 1);
1.1 paf 87: }
E-mail: