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

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.33    ! parser      8: static const char *RCSId="$Id: double.C,v 1.32 2001/06/28 07:44:17 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 
1.33    ! parser     77: const String* sql_result_string(Request& r, const String& method_name, 
        !            78:                                                                MethodParams *params);
1.29      parser     79: 
                     80: static void _sql(Request& r, const String& method_name, MethodParams *params) {
                     81:        Pool& pool=r.pool();
                     82: 
1.33    ! parser     83:        const String *string=sql_result_string(r, method_name, params);
        !            84:        double val=string?string->as_int():params->as_double(1, r);
1.29      parser     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:        
1.33    ! parser    118:        // ^double:sql[query](default)
        !           119:        // ^double:sql[query](default)(offset)
        !           120:        add_native_method("sql", Method::CT_STATIC, _sql, 2, 3);
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: