Annotation of parser3/src/classes/double.C, revision 1.32

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

E-mail: