Annotation of parser3/src/classes/double.C, revision 1.12
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.12 ! paf 6: $Id: double.C,v 1.11 2001/03/12 21:17:59 paf Exp $
1.1 paf 7: */
8:
9: #include "pa_request.h"
10: #include "_double.h"
11: #include "pa_vdouble.h"
12: #include "pa_vint.h"
13:
14: // global var
15:
16: VClass *double_class;
17:
18: // methods
19:
1.10 paf 20: static void _int(Request& r, const String&, Array *) {
1.1 paf 21: Pool& pool=r.pool();
22: VDouble *vdouble=static_cast<VDouble *>(r.self);
1.11 paf 23: Value& value=*new(pool) VInt(pool, (int)vdouble->get_double());
1.3 paf 24: r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1 paf 25: }
26:
1.10 paf 27: static void _double(Request& r, const String&, Array *) {
1.1 paf 28: Pool& pool=r.pool();
29: VDouble *vdouble=static_cast<VDouble *>(r.self);
30: Value& value=*new(pool) VDouble(pool, vdouble->get_double());
1.3 paf 31: r.wcontext->write(value, String::Untaint_lang::NO /*always object, not string*/);
1.1 paf 32: }
33:
1.10 paf 34: static void _inc(Request& r, const String&, Array *params) {
1.1 paf 35: VDouble *vdouble=static_cast<VDouble *>(r.self);
1.6 paf 36: double increment=params->size()?
1.10 paf 37: r.process(
1.6 paf 38: *static_cast<Value *>(params->get(0)),
39: 0/*no name*/,
1.8 paf 40: false/*don't intercept string*/).get_double():1;
1.1 paf 41: vdouble->inc(increment);
42: }
43:
1.12 ! paf 44: static void _format(Request& r, const String& method_name, Array *params) {
! 45: Pool& pool=r.pool();
! 46:
! 47: Value& fmt=*static_cast<Value *>(params->get(0));
! 48: // forcing ^format[this param type]
! 49: r.fail_if_junction_(true, fmt,
! 50: method_name, "fmt must not be junction");
! 51:
! 52: char *buf=format(pool, r.self->get_double(), fmt.as_string().cstr());
! 53:
! 54: String *string=new(pool) String(pool);
! 55: r.wcontext->write(string->APPEND_CONST(buf),
! 56: String::Untaint_lang::NO /*always object, not string*/);
! 57: }
! 58:
1.2 paf 59: void initialize_double_class(Pool& pool, VClass& vclass) {
1.9 paf 60: // ^double.int[]
61: vclass.add_native_method("int", _int, 0, 0);
62:
63: // ^double.double[]
64: vclass.add_native_method("double", _double, 0, 0);
65:
66: // ^double.inc[]
67: // ^double.inc[offset]
68: vclass.add_native_method("inc", _inc, 0, 1);
1.12 ! paf 69:
! 70: // ^string.format[]
! 71: vclass.add_native_method("format", _format, 1, 1);
1.1 paf 72: }
E-mail: