Annotation of parser3/src/classes/double.C, revision 1.30
1.20 paf 1: /** @file
2: Parser: @b double parser class.
3:
1.4 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.20 paf 5:
1.5 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.4 paf 7:
1.30 ! parser 8: $Id: double.C,v 1.29 2001/05/21 16:55:52 parser Exp $
1.1 paf 9: */
10:
1.24 paf 11: #include "classes.h"
1.1 paf 12: #include "pa_request.h"
13: #include "pa_vdouble.h"
14: #include "pa_vint.h"
15:
1.22 paf 16: // externs
1.1 paf 17:
1.22 paf 18: void _string_format(Request& r, const String& method_name, MethodParams *);
19:
20: // defines
21:
22: #define DOUBLE_CLASS_NAME "double"
23:
24: // class
25:
26: class MDouble : public Methoded {
27: public:
28: MDouble(Pool& pool);
1.26 paf 29: public: // Methoded
1.30 ! parser 30: bool used_directly() { return true; }
1.22 paf 31: };
1.1 paf 32:
33: // methods
34:
1.27 paf 35: static void _int(Request& r, const String& method_name, MethodParams *) {
1.1 paf 36: Pool& pool=r.pool();
37: VDouble *vdouble=static_cast<VDouble *>(r.self);
1.28 parser 38: Value& result=*new(pool) VInt(pool, vdouble->as_int());
1.27 paf 39: result.set_name(method_name);
40: r.write_no_lang(result);
1.1 paf 41: }
42:
1.27 paf 43: static void _double(Request& r, const String& method_name, MethodParams *) {
1.1 paf 44: Pool& pool=r.pool();
45: VDouble *vdouble=static_cast<VDouble *>(r.self);
1.27 paf 46: Value& result=*new(pool) VDouble(pool, vdouble->as_double());
47: result.set_name(method_name);
48: r.write_no_lang(result);
1.1 paf 49: }
50:
1.14 paf 51: typedef void (*vdouble_op_func_ptr)(VDouble& vdouble, double param);
52:
53: static void __inc(VDouble& vdouble, double param) { vdouble.inc(param); }
54: static void __dec(VDouble& vdouble, double param) { vdouble.inc(-param); }
55: static void __mul(VDouble& vdouble, double param) { vdouble.mul(param); }
56: static void __div(VDouble& vdouble, double param) { vdouble.div(param); }
57: static void __mod(VDouble& vdouble, double param) { vdouble.mod((int)param); }
58:
1.21 paf 59: static void vdouble_op(Request& r, MethodParams *params,
1.14 paf 60: vdouble_op_func_ptr func) {
1.1 paf 61: VDouble *vdouble=static_cast<VDouble *>(r.self);
1.14 paf 62: double param=params->size()?
1.10 paf 63: r.process(
1.21 paf 64: params->get(0),
1.6 paf 65: 0/*no name*/,
1.18 paf 66: false/*don't intercept string*/).as_double():1/*used in inc/dec*/;
1.14 paf 67: (*func)(*vdouble, param);
1.1 paf 68: }
69:
1.21 paf 70: static void _inc(Request& r, const String&, MethodParams *params) { vdouble_op(r, params, &__inc); }
71: static void _dec(Request& r, const String&, MethodParams *params) { vdouble_op(r, params, &__dec); }
72: static void _mul(Request& r, const String&, MethodParams *params) { vdouble_op(r, params, &__mul); }
73: static void _div(Request& r, const String&, MethodParams *params) { vdouble_op(r, params, &__div); }
74: static void _mod(Request& r, const String&, MethodParams *params) { vdouble_op(r, params, &__mod); }
1.16 paf 75:
1.29 parser 76: // from string.C
77: extern
78: String& sql_result_string(Request& r, const String& method_name, MethodParams *params);
79:
80: static void _sql(Request& r, const String& method_name, MethodParams *params) {
81: Pool& pool=r.pool();
82:
83: double val=sql_result_string(r, method_name, params).as_double();
84:
85: VDouble& result=*new(pool) VDouble(pool, val);
86: result.set_name(method_name);
87: r.write_assign_lang(result);
88: }
89:
1.22 paf 90: // constructor
91:
92: MDouble::MDouble(Pool& apool) : Methoded(apool) {
93: set_name(*NEW String(pool(), DOUBLE_CLASS_NAME));
1.30 ! parser 94:
1.14 paf 95:
1.9 paf 96: // ^double.int[]
1.22 paf 97: add_native_method("int", Method::CT_DYNAMIC, _int, 0, 0);
1.9 paf 98:
99: // ^double.double[]
1.22 paf 100: add_native_method("double", Method::CT_DYNAMIC, _double, 0, 0);
1.9 paf 101:
1.14 paf 102: // ^double.inc[]
1.9 paf 103: // ^double.inc[offset]
1.22 paf 104: add_native_method("inc", Method::CT_DYNAMIC, _inc, 0, 1);
1.14 paf 105: // ^double.dec[]
106: // ^double.dec[offset]
1.22 paf 107: add_native_method("dec", Method::CT_DYNAMIC, _dec, 0, 1);
1.14 paf 108: // ^double.mul[k]
1.22 paf 109: add_native_method("mul", Method::CT_DYNAMIC, _mul, 1, 1);
1.14 paf 110: // ^double.div[d]
1.22 paf 111: add_native_method("div", Method::CT_DYNAMIC, _div, 1, 1);
1.14 paf 112: // ^double.mod[offset]
1.22 paf 113: add_native_method("mod", Method::CT_DYNAMIC, _mod, 1, 1);
1.12 paf 114:
1.20 paf 115: // ^double.format{format}
1.22 paf 116: add_native_method("format", Method::CT_DYNAMIC, _string_format, 1, 1);
1.29 parser 117:
118: // ^double:sql[query]
119: // ^double:sql[query](offset)
120: add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
1.22 paf 121: }
122: // global variable
123:
124: Methoded *double_class;
125:
126: // creator
127:
128: Methoded *MDouble_create(Pool& pool) {
129: return double_class=new(pool) MDouble(pool);
1.1 paf 130: }
E-mail: