Diff for /parser3/src/classes/int.C between versions 1.16 and 1.56

version 1.16, 2001/03/27 16:35:52 version 1.56, 2007/02/03 18:08:38
Line 1 Line 1
 /*  /** @file
         Parser          Parser: @b int parser class.
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)  
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)  
   
         $Id$          Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
           Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
   static const char * const IDENT_INT_C="$Date$";
   
   #include "classes.h"
   #include "pa_vmethod_frame.h"
   
 #include "pa_request.h"  #include "pa_request.h"
 #include "_int.h"  
 #include "pa_vdouble.h"  #include "pa_vdouble.h"
 #include "pa_vint.h"  #include "pa_vint.h"
 #include "_string.h"  #include "pa_vbool.h"
   
   // externs
   
   void _string_format(Request& r, MethodParams&);
   
 // global var  // class
   
 VStateless_class *int_class;  class MInt: public Methoded {
   public:
           MInt();
   public: // Methoded
           bool used_directly() { return true; }
   };
   
   // global variable
   
   DECLARE_CLASS_VAR(int, new MInt, 0);
   
 // methods  // methods
   
 static void _int(Request& r, const String&, Array *) {  static void _int(Request& r, MethodParams& params) {
         Pool& pool=r.pool();          // just checking (default) syntax validity, never really using it here, just for string.int compatibility
         VInt *vint=static_cast<VInt *>(r.self);          if(params.count()>0)
         Value& value=*new(pool) VInt(pool, vint->get_int());                  params.as_int(0, "default must be int", r);
         r.write_no_lang(value);  
           VInt& vint=GET_SELF(r, VInt);
           r.write_no_lang(*new VInt(vint.get_int()));
   }
   
   static void _double(Request& r, MethodParams& params) {
           // just checking (default) syntax validity, never really using it here, just for string.double compatibility
           if(params.count()>0)
                   params.as_double(0, "default must be double", r);
   
           VInt& vint=GET_SELF(r, VInt);
           r.write_no_lang(*new VDouble(vint.as_double()));
 }  }
   
 static void _double(Request& r, const String&, Array *) {  static void _bool(Request& r, MethodParams& params) {
         Pool& pool=r.pool();          // just checking (default) syntax validity, never really using it here, just for string.bool compatibility
         VInt *vint=static_cast<VInt *>(r.self);          if(params.count()>0)
         Value& value=*new(pool) VDouble(pool, vint->as_double());                  params.as_bool(0, "default must be bool", r);
         r.write_no_lang(value);  
           VInt& vint=GET_SELF(r, VInt);
           r.write_no_lang(*new VBool(vint.as_bool()));
 }  }
   
 typedef void (*vint_op_func_ptr)(VInt& vint, double param);  typedef void (*vint_op_func_ptr)(VInt& vint, double param);
Line 40  static void __mul(VInt& vint, double par Line 69  static void __mul(VInt& vint, double par
 static void __div(VInt& vint, double param) { vint.div(param); }  static void __div(VInt& vint, double param) { vint.div(param); }
 static void __mod(VInt& vint, double param) { vint.mod((int)param); }  static void __mod(VInt& vint, double param) { vint.mod((int)param); }
   
 static void vint_op(Request& r, Array *params,   static void vint_op(Request& r, MethodParams& params, 
                                          vint_op_func_ptr func) {                                           vint_op_func_ptr func) {
         VInt *vint=static_cast<VInt *>(r.self);          VInt& vint=GET_SELF(r, VInt);
         double param=params->size()?          double param=params.count()?params.as_double(0, "param must be numerical", r):1;
                 r.process(          (*func)(vint, param);
                         *static_cast<Value *>(params->get(0)),  }
                         0/*no name*/,  
                         false/*don't intercept string*/).as_double():1;  
         (*func)(*vint, param);  
 }  
   
 static void _inc(Request& r, const String&, Array *params) { vint_op(r, params, &__inc); }  
 static void _dec(Request& r, const String&, Array *params) { vint_op(r, params, &__dec); }  
 static void _mul(Request& r, const String&, Array *params) { vint_op(r, params, &__mul); }  
 static void _div(Request& r, const String&, Array *params) { vint_op(r, params, &__div); }  
 static void _mod(Request& r, const String&, Array *params) { vint_op(r, params, &__mod); }  
   
 // initialize  static void _inc(Request& r, MethodParams& params) { vint_op(r, params, &__inc); }
   static void _dec(Request& r, MethodParams& params) { vint_op(r, params, &__dec); }
   static void _mul(Request& r, MethodParams& params) { vint_op(r, params, &__mul); }
   static void _div(Request& r, MethodParams& params) { vint_op(r, params, &__div); }
   static void _mod(Request& r, MethodParams& params) { vint_op(r, params, &__mod); }
   
   // from string.C
   extern 
   const String* sql_result_string(Request& r, MethodParams& params,
                                   HashStringValue*& options, Value*& default_code);
   static void _sql(Request& r, MethodParams& params) {
           int val;
           HashStringValue* options;
           Value* default_code=0;
           if(const String* string=sql_result_string(r, params, options, default_code))
                   val=string->as_int();
           else
                   if(default_code)
                           val=r.process_to_value(*default_code).as_int();
                   else {
                           throw Exception("parser.runtime",
                                   0,
                                   "produced no result, but no default option specified");
                   }
           r.write_no_lang(*new VInt(val));
   }
   
   // constructor
   
 void initialize_int_class(Pool& pool, VStateless_class& vclass) {  MInt::MInt(): Methoded("int") {
         // ^int.int[]          // ^int.int[]
         vclass.add_native_method("int", _int, 0, 0);          add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);
   
         // ^int.double[]          // ^int.double[]
         vclass.add_native_method("double", _double, 0, 0);          add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1);
   
           // ^double.bool[]
           add_native_method("bool", Method::CT_DYNAMIC, _bool, 0, 1);
   
         // ^int.inc[]           // ^int.inc[] 
         // ^int.inc[offset]          // ^int.inc[offset]
         vclass.add_native_method("inc", _inc, 0, 1);          add_native_method("inc", Method::CT_DYNAMIC, _inc, 0, 1);
         // ^int.dec[]           // ^int.dec[] 
         // ^int.dec[offset]          // ^int.dec[offset]
         vclass.add_native_method("dec", _dec, 0, 1);          add_native_method("dec", Method::CT_DYNAMIC, _dec, 0, 1);
         // ^int.mul[k]           // ^int.mul[k] 
         vclass.add_native_method("mul", _mul, 1, 1);          add_native_method("mul", Method::CT_DYNAMIC, _mul, 1, 1);
         // ^int.div[d]          // ^int.div[d]
         vclass.add_native_method("div", _div, 1, 1);          add_native_method("div", Method::CT_DYNAMIC, _div, 1, 1);
         // ^int.mod[offset]          // ^int.mod[offset]
         vclass.add_native_method("mod", _mod, 1, 1);          add_native_method("mod", Method::CT_DYNAMIC, _mod, 1, 1);
   
   
           // ^int.format{format}
           add_native_method("format", Method::CT_DYNAMIC, _string_format, 1, 1);
   
         // ^int.format[]          // ^sql[query]
         vclass.add_native_method("format", _string_format, 1, 1);          // ^sql[query][$.limit(1) $.offset(2) $.default(0)]
           add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
 }  }

Removed from v.1.16  
changed lines
  Added in v.1.56


E-mail: