--- parser3/src/classes/hash.C 2016/07/14 17:06:30 1.129 +++ parser3/src/classes/hash.C 2016/10/06 19:41:36 1.134 @@ -17,7 +17,7 @@ #include "pa_vbool.h" #include "pa_vmethod_frame.h" -volatile const char * IDENT_HASH_C="$Id: hash.C,v 1.129 2016/07/14 17:06:30 moko Exp $"; +volatile const char * IDENT_HASH_C="$Id: hash.C,v 1.134 2016/10/06 19:41:36 moko Exp $"; // class @@ -193,11 +193,11 @@ VBool Hash_sql_event_handlers::only_one_ static void _create_or_add(Request& r, MethodParams& params) { if(params.count()) { Value& vsrc=params.as_no_junction(0, PARAM_MUST_BE_HASH); - VHash& self=GET_SELF(r, VHash); - HashStringValue* src_hash; + VHashBase& self=GET_SELF(r, VHashBase); HashStringValue* self_hash=&(self.hash()); + HashStringValue* src_hash; - if(VHash* src=static_cast(vsrc.as(VHASH_TYPE))) { + if(VHashBase* src=static_cast(vsrc.as(VHASH_TYPE))) { src_hash=&(src->hash()); if(src_hash==self_hash) // same: doing nothing @@ -216,7 +216,7 @@ static void _create_or_add(Request& r, M static void _sub(Request& r, MethodParams& params) { if(HashStringValue* src=params.as_hash(0, "param")) { - HashStringValue* self=&(GET_SELF(r, VHash).hash()); + HashStringValue* self=&(GET_SELF(r, VHashBase).hash()); if(src==self) { // same: clearing self->clear(); return; @@ -225,15 +225,12 @@ static void _sub(Request& r, MethodParam } } -static void copy_all_dontoverwrite_to( - HashStringValue::key_type key, - HashStringValue::value_type value, - HashStringValue* dest) { +static void copy_all_dontoverwrite_to(HashStringValue::key_type key, HashStringValue::value_type value, HashStringValue* dest) { dest->put_dont_replace(key, value); } static void _union(Request& r, MethodParams& params) { // dest = copy of self - Value& result=*new VHash(GET_SELF(r, VHash).hash()); + Value& result=*new VHash(GET_SELF(r, VHashBase).hash()); // dest += b if(HashStringValue* src=params.as_hash(0, "param")) src->for_each(copy_all_dontoverwrite_to, result.get_hash()); @@ -248,10 +245,7 @@ struct Copy_intersection_to_info { HashStringValue* dest; }; #endif -static void copy_intersection_to( - HashStringValue::key_type key, - HashStringValue::value_type value, - Copy_intersection_to_info *info) { +static void copy_intersection_to(HashStringValue::key_type key, HashStringValue::value_type value, Copy_intersection_to_info *info) { if(info->b->get(key)) info->dest->put_dont_replace(key, value); } @@ -260,17 +254,14 @@ static void _intersection(Request& r, Me // dest += b if(HashStringValue* b=params.as_hash(0, "param")) { Copy_intersection_to_info info={b, result.get_hash()}; - GET_SELF(r, VHash).hash().for_each(copy_intersection_to, &info); + GET_SELF(r, VHashBase).hash().for_each(copy_intersection_to, &info); } // return result r.write_no_lang(result); } -static bool intersects( - HashStringValue::key_type key, - HashStringValue::value_type /*value*/, - HashStringValue* b) { +static bool intersects( HashStringValue::key_type key, HashStringValue::value_type /*value*/, HashStringValue* b) { return b->get(key)!=0; } @@ -278,7 +269,7 @@ static void _intersects(Request& r, Meth bool result=false; if(HashStringValue* b=params.as_hash(0, "param")) { - HashStringValue* self=&(GET_SELF(r, VHash).hash()); + HashStringValue* self=&(GET_SELF(r, VHashBase).hash()); if(b==self) { r.write_no_lang(VBool::get(true)); return; @@ -318,19 +309,19 @@ static void _sql(Request& r, MethodParam } if(Value* vlimit=options->get(sql_limit_name)) { valid_options++; - limit=(ulong)r.process_to_value(*vlimit).as_double(); + limit=(ulong)r.process(*vlimit).as_double(); } if(Value* voffset=options->get(sql_offset_name)) { valid_options++; - offset=(ulong)r.process_to_value(*voffset).as_double(); + offset=(ulong)r.process(*voffset).as_double(); } if(Value* vdistinct=options->get(sql_distinct_name)) { valid_options++; - distinct=r.process_to_value(*vdistinct).as_bool(); + distinct=r.process(*vdistinct).as_bool(); } if(Value* vvalue_type=options->get(sql_value_type_name)) { valid_options++; - value_type=get_value_type(r.process_to_value(*vvalue_type)); + value_type=get_value_type(r.process(*vvalue_type)); } if(valid_options!=options->count()) throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); @@ -345,7 +336,7 @@ static void _sql(Request& r, MethodParam const String& statement_string=r.process_to_string(statement); const char* statement_cstr=statement_string.untaint_cstr(r.flang, r.connection()); - HashStringValue& hash=GET_SELF(r, VHash).hash(); + HashStringValue& hash=GET_SELF(r, VHashBase).hash(); hash.clear(); Hash_sql_event_handlers handlers( statement_string, statement_cstr, @@ -364,10 +355,7 @@ static void _sql(Request& r, MethodParam unmarshal_bind_updates(*bind, placeholders_count, placeholders); } -static void keys_collector( - HashStringValue::key_type key, - HashStringValue::value_type, - Table *table) { +static void keys_collector(HashStringValue::key_type key, HashStringValue::value_type, Table *table) { Table::element_type row(new ArrayString(1)); *row+=new String(key, String::L_TAINTED); *table+=row; @@ -383,24 +371,24 @@ static void _keys(Request& r, MethodPara *columns+=keys_column_name; Table* table=new Table(columns); - GET_SELF(r, VHash).hash().for_each(keys_collector, table); + GET_SELF(r, VHashBase).hash().for_each(keys_collector, table); r.write_no_lang(*new VTable(table)); } static void _count(Request& r, MethodParams&) { - r.write_no_lang(*new VInt(GET_SELF(r, VHash).hash().count())); + r.write_no_lang(*new VInt(GET_SELF(r, VHashBase).hash().count())); } static void _delete(Request& r, MethodParams& params) { if(params.count()>0) - GET_SELF(r, VHash).hash().remove(params.as_string(0, "key must be string")); + GET_SELF(r, VHashBase).hash().remove(params.as_string(0, "key must be string")); else - GET_SELF(r, VHash).hash().clear(); + GET_SELF(r, VHashBase).hash().clear(); } static void _contains(Request& r, MethodParams& params) { - VHash& self=GET_SELF(r, VHash); + VHashBase& self=GET_SELF(r, VHashBase); const String& key_name=params.as_string(0, "key must be string"); bool result=SYMBOLS_EQ(key_name,_DEFAULT_SYMBOL) ? (self.get_default() != 0) : self.hash().contains(key_name); r.write_no_lang(VBool::get(result)); @@ -412,14 +400,13 @@ static void _foreach(Request& r, MethodP const String* key_var_name=¶ms.as_string(0, "key-var name must be string"); const String* value_var_name=¶ms.as_string(1, "value-var name must be string"); Value* body_code=¶ms.as_junction(2, "body must be code"); - Value* delim_maybe_code=params.count()>3?params.get(3):0; + Value* delim_maybe_code=params.count()>3?¶ms[3]:0; Value& caller=*r.get_method_frame()->caller(); if(key_var_name->is_empty()) key_var_name=0; if(value_var_name->is_empty()) value_var_name=0; - VHash& self=GET_SELF(r, VHash); - HashStringValue& hash=self.hash(); + HashStringValue& hash=GET_SELF(r, VHashBase).hash(); if(delim_maybe_code){ // delimiter set bool need_delim=false;; @@ -432,7 +419,7 @@ static void _foreach(Request& r, MethodP if(value_var_name) r.put_element(caller, *value_var_name, i.value()); - StringOrValue sv_processed=r.process(*body_code); + Value& sv_processed=r.process(*body_code); Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); const String* s_processed=sv_processed.get_string(); @@ -517,8 +504,7 @@ static void _sort(Request& r, MethodPara const String* value_var=value_var_name.is_empty()? 0 : &value_var_name; VMethodFrame* context=r.get_method_frame()->caller(); - VHash& self=GET_SELF(r, VHash); - HashStringValue& hash=self.hash(); + HashStringValue& hash=GET_SELF(r, VHashBase).hash(); int count=hash.count(); Hash_seq_item* seq=new(PointerFreeGC) Hash_seq_item[count]; @@ -531,7 +517,7 @@ static void _sort(Request& r, MethodPara if(value_var) r.put_element(*context, *value_var, i.value()); - Value& value=r.process_to_value(key_maker); + Value& value=r.process(key_maker); if(pos==0) // determining key values type by first one key_values_are_strings=value.is_string(); @@ -546,7 +532,7 @@ static void _sort(Request& r, MethodPara if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) for(pos=0; pos 1) { const String& stype=params.as_string(1, "type must be string"); @@ -584,7 +570,7 @@ static void _at(Request& r, MethodParams throw Exception(PARSER_RUNTIME, &stype, "type must be 'key', 'value' or 'hash'"); } - Value& vwhence=*params.get(0); + Value& vwhence=params[0]; if(vwhence.is_string()) { const String& swhence=*vwhence.get_string(); if(swhence == "last") @@ -594,7 +580,7 @@ static void _at(Request& r, MethodParams &swhence, "whence must be 'first', 'last' or expression"); } else { - pos=r.process_to_value(vwhence).as_int(); + pos=r.process(vwhence).as_int(); if(pos < 0) pos+=count; }