--- parser3/src/classes/double.C 2001/05/21 16:55:52 1.29 +++ parser3/src/classes/double.C 2001/10/09 07:06:00 1.38 @@ -2,10 +2,9 @@ Parser: @b double parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - $Id: double.C,v 1.29 2001/05/21 16:55:52 parser Exp $ + $Id: double.C,v 1.38 2001/10/09 07:06:00 parser Exp $ */ #include "classes.h" @@ -27,7 +26,7 @@ class MDouble : public Methoded { public: MDouble(Pool& pool); public: // Methoded - bool used_directly() { return false; } + bool used_directly() { return true; } }; // methods @@ -60,10 +59,7 @@ static void vdouble_op(Request& r, Metho vdouble_op_func_ptr func) { VDouble *vdouble=static_cast(r.self); double param=params->size()? - r.process( - params->get(0), - 0/*no name*/, - false/*don't intercept string*/).as_double():1/*used in inc/dec*/; + params->as_double(0, "param must be double", r):1/*used in inc/dec*/; (*func)(*vdouble, param); } @@ -75,13 +71,33 @@ static void _mod(Request& r, const Strin // from string.C extern -String& sql_result_string(Request& r, const String& method_name, MethodParams *params); +const String* sql_result_string(Request& r, const String& method_name, + MethodParams *params, + Hash *&options); static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - double val=sql_result_string(r, method_name, params).as_double(); - + double val; + Hash *options; + if(const String *string=sql_result_string(r, method_name, params, options)) + val=string->as_double(); + else + if(options) { + if(Value *vdefault=(Value *)options->get(*sql_default_name)) + val=r.process(*vdefault).as_double(); + else { + PTHROW(0, 0, + &method_name, + "produced no result, but no default option specified"); + val=0; //calm, compiler + } + } else { + PTHROW(0, 0, + &method_name, + "produced no result, but no options (no default) specified"); + val=0; //calm, compiler + } VDouble& result=*new(pool) VDouble(pool, val); result.set_name(method_name); r.write_assign_lang(result); @@ -92,6 +108,7 @@ static void _sql(Request& r, const Strin MDouble::MDouble(Pool& apool) : Methoded(apool) { set_name(*NEW String(pool(), DOUBLE_CLASS_NAME)); + // ^double.int[] add_native_method("int", Method::CT_DYNAMIC, _int, 0, 0); @@ -114,8 +131,8 @@ MDouble::MDouble(Pool& apool) : Methoded // ^double.format{format} add_native_method("format", Method::CT_DYNAMIC, _string_format, 1, 1); - // ^double:sql[query] - // ^double:sql[query](offset) + // ^sql[query] + // ^sql[query][$.limit(1) $.offset(2) $.default(0.0)] add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); } // global variable