--- parser3/src/classes/hash.C 2010/11/26 06:40:01 1.109 +++ parser3/src/classes/hash.C 2012/06/13 22:53:47 1.115 @@ -1,12 +1,10 @@ /** @file Parser: @b hash parser class. - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HASH_C="$Date: 2010/11/26 06:40:01 $"; - #include "classes.h" #include "pa_vmethod_frame.h" @@ -18,6 +16,8 @@ static const char * const IDENT_HASH_C=" #include "pa_vbool.h" #include "pa_vmethod_frame.h" +volatile const char * IDENT_HASH_C="$Id: hash.C,v 1.115 2012/06/13 22:53:47 moko Exp $"; + // class class MHash: public Methoded { @@ -191,31 +191,31 @@ 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"); - if(HashStringValue* src=vsrc.get_hash()) { - VHash& self=GET_SELF(r, VHash); - HashStringValue* self_hash=&(self.hash()); - if(src==self_hash) // same: doing nothing + Value& vsrc=params.as_no_junction(0, PARAM_MUST_BE_HASH); + VHash& self=GET_SELF(r, VHash); + HashStringValue* src_hash; + HashStringValue* self_hash=&(self.hash()); + + if(VHash* src=static_cast(vsrc.as(VHASH_TYPE))) { + src_hash=&(src->hash_ro()); + + if(src_hash==self_hash) // same: doing nothing return; - src->for_each(copy_all_overwrite_to, self_hash); - if(VHash* vhash_src=static_cast(vsrc.as(VHASH_TYPE))) - { - if(Value* vdefault=vhash_src->get_default()) - { - if(vdefault->is_defined()) - { - self.set_default(vdefault); - } - } - } + if(Value* vdefault=src->get_default()) + if(vdefault->is_defined()) + self.set_default(vdefault); + } else { + src_hash=vsrc.get_hash(); } + + if(src_hash) + src_hash->for_each(copy_all_overwrite_to, self_hash); } } static void _sub(Request& r, MethodParams& params) { - Value& vsrc=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* src=vsrc.get_hash()) { + if(HashStringValue* src=params.as_hash(0, "param")) { HashStringValue* self=&(GET_SELF(r, VHash).hash()); if(src==self) { // same: clearing self->clear(); @@ -235,8 +235,7 @@ static void _union(Request& r, MethodPar // dest = copy of self Value& result=*new VHash(GET_SELF(r, VHash).hash()); // dest += b - Value& vsrc=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* src=vsrc.get_hash()) + if(HashStringValue* src=params.as_hash(0, "param")) src->for_each(copy_all_dontoverwrite_to, result.get_hash()); // return result @@ -259,8 +258,7 @@ static void copy_intersection_to( static void _intersection(Request& r, MethodParams& params) { Value& result=*new VHash; // dest += b - Value& vb=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* b=vb.get_hash()) { + 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); } @@ -279,8 +277,7 @@ static bool intersects( static void _intersects(Request& r, MethodParams& params) { bool result=false; - Value& vb=params.as_no_junction(0, "param must be hash"); - if(HashStringValue* b=vb.get_hash()) + if(HashStringValue* b=params.as_hash(0, "param")) result=GET_SELF(r, VHash).hash().first_that(intersects, b)!=0; // return result @@ -306,36 +303,32 @@ static void _sql(Request& r, MethodParam ulong offset=0; bool distinct=false; Table2hash_value_type value_type=C_HASH; - if(params.count()>1) { - Value& voptions=params.as_no_junction(1, "options must be hash, not code"); - if(voptions.is_defined() && !voptions.is_string()) - if(HashStringValue* options=voptions.get_hash()) { - int valid_options=0; - if(Value* vbind=options->get(sql_bind_name)) { - valid_options++; - bind=vbind->get_hash(); - } - if(Value* vlimit=options->get(sql_limit_name)) { - valid_options++; - limit=(ulong)r.process_to_value(*vlimit).as_double(); - } - if(Value* voffset=options->get(sql_offset_name)) { - valid_options++; - offset=(ulong)r.process_to_value(*voffset).as_double(); - } - if(Value* vdistinct=options->get(sql_distinct_name)) { - valid_options++; - distinct=r.process_to_value(*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)); - } - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); - } else - throw Exception(PARSER_RUNTIME, 0, OPTIONS_MUST_BE_HASH); - } + if(params.count()>1) + if(HashStringValue* options=params.as_hash(1, "sql options")) { + int valid_options=0; + if(Value* vbind=options->get(sql_bind_name)) { + valid_options++; + bind=vbind->get_hash(); + } + if(Value* vlimit=options->get(sql_limit_name)) { + valid_options++; + limit=(ulong)r.process_to_value(*vlimit).as_double(); + } + if(Value* voffset=options->get(sql_offset_name)) { + valid_options++; + offset=(ulong)r.process_to_value(*voffset).as_double(); + } + if(Value* vdistinct=options->get(sql_distinct_name)) { + valid_options++; + distinct=r.process_to_value(*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)); + } + if(valid_options!=options->count()) + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); + } SQL_Driver::Placeholder* placeholders=0; uint placeholders_count=0; @@ -384,13 +377,13 @@ 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, VHash).hash_ro().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, VHash).hash_ro().count())); } static void _delete(Request& r, MethodParams& params) { @@ -399,7 +392,7 @@ static void _delete(Request& r, MethodPa } static void _contains(Request& r, MethodParams& params) { - bool result=GET_SELF(r, VHash).hash().contains(params.as_string(0, "key must be string")); + bool result=GET_SELF(r, VHash).hash_ro().contains(params.as_string(0, "key must be string")); r.write_no_lang(VBool::get(result)); } @@ -463,13 +456,13 @@ static void _foreach(Request& r, MethodP }; VHash& self=GET_SELF(r, VHash); - HashStringValue& hash=self.hash(); + HashStringValue& hash=self.hash_ro(); VHash_lock lock(self); hash.first_that(one_foreach_cycle, &info); } static void _at(Request& r, MethodParams& params) { - HashStringValue& hash=GET_SELF(r, VHash).hash(); + HashStringValue& hash=GET_SELF(r, VHash).hash_ro(); size_t count=hash.count(); int pos=0;