--- parser3/src/classes/hash.C 2001/11/01 15:11:36 1.27 +++ parser3/src/classes/hash.C 2002/01/16 10:28:33 1.32 @@ -2,9 +2,9 @@ Parser: @b hash parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: hash.C,v 1.27 2001/11/01 15:11:36 paf Exp $ + $Id: hash.C,v 1.32 2002/01/16 10:28:33 paf Exp $ */ #include "classes.h" @@ -95,14 +95,13 @@ static void copy_all_overwrite_to(const Hash& dest=*static_cast(info); dest.put(key, value); } - static void _create_or_add(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); if(params->size()) { Value& vb=params->as_no_junction(0, "param must be hash"); if(Hash *b=vb.get_hash(&method_name)) - b->for_each(copy_all_overwrite_to, &static_cast(r.self)->hash()); + b->for_each(copy_all_overwrite_to, &static_cast(r.self)->hash(&method_name)); } } @@ -110,25 +109,23 @@ static void remove_key_from(const Hash:: Hash& dest=*static_cast(info); dest.remove(key); } - static void _sub(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Value& vb=params->as_no_junction(0, "param must be hash"); if(Hash *b=vb.get_hash(&method_name)) - b->for_each(remove_key_from, &static_cast(r.self)->hash()); + b->for_each(remove_key_from, &static_cast(r.self)->hash(&method_name)); } static void copy_all_dontoverwrite_to(const Hash::Key& key, Hash::Val *value, void *info) { Hash& dest=*static_cast(info); dest.put_dont_replace(key, value); } - static void _union(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); // dest = copy of self - Hash& dest=*new(pool) Hash(static_cast(r.self)->hash()); + Hash& dest=*new(pool) Hash(static_cast(r.self)->hash(&method_name)); // dest += b Value& vb=params->as_no_junction(0, "param must be hash"); if(Hash *b=vb.get_hash(&method_name)) @@ -153,7 +150,6 @@ static void copy_intersection_to(const H if(i.b->get(key)) i.dest->put_dont_replace(key, value); } - static void _intersection(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -166,7 +162,7 @@ static void _intersection(Request& r, co b, &dest }; - static_cast(r.self)->hash().for_each(copy_intersection_to, &info); + static_cast(r.self)->hash(&method_name).for_each(copy_intersection_to, &info); } // return result @@ -189,7 +185,7 @@ static void _intersects(Request& r, cons // dest += b Value& vb=params->as_no_junction(0, "param must be hash"); if(Hash *b=vb.get_hash(&method_name)) - yes=static_cast(r.self)->hash().first_that(intersects, b)!=0; + yes=static_cast(r.self)->hash(&method_name).first_that(intersects, b)!=0; // return result Value& result=*new(pool) VBool(pool, yes); @@ -201,11 +197,6 @@ static void _intersects(Request& r, cons static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - if(!r.connection) - throw Exception(0, 0, - &method_name, - "without connect"); - Value& statement=params->as_junction(0, "statement must be code"); ulong limit=0; @@ -223,13 +214,13 @@ static void _sql(Request& r, const Strin Temp_lang temp_lang(r, String::UL_SQL); const String& statement_string=r.process(statement).as_string(); const char *statement_cstr= - statement_string.cstr(String::UL_UNSPECIFIED, r.connection); - Hash& hash=static_cast(r.self)->hash(); + statement_string.cstr(String::UL_UNSPECIFIED, r.connection(&method_name)); + Hash& hash=static_cast(r.self)->hash(&method_name); hash.clear(); Hash_sql_event_handlers handlers(pool, method_name, statement_string, statement_cstr, hash); - r.connection->query( + r.connection(&method_name)->query( statement_cstr, offset, limit, handlers); } @@ -249,7 +240,7 @@ static void _keys(Request& r, const Stri columns+=new(pool) String(pool, "key"); Table& table=*new(pool) Table(pool, &method_name, &columns); - static_cast(r.self)->hash().for_each(keys_collector, &table); + static_cast(r.self)->hash(&method_name).for_each(keys_collector, &table); VTable& result=*new(pool) VTable(pool, &table); result.set_name(method_name); @@ -259,7 +250,7 @@ static void _keys(Request& r, const Stri static void _count(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); - Value& result=*new(pool) VInt(pool, static_cast(r.self)->hash().size()); + Value& result=*new(pool) VInt(pool, static_cast(r.self)->hash(&method_name).size()); result.set_name(method_name); r.write_no_lang(result); } @@ -267,7 +258,7 @@ static void _count(Request& r, const Str static void _delete(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - static_cast(r.self)->hash().remove(params->as_string(0, "key must be string")); + static_cast(r.self)->hash(&method_name).remove(params->as_string(0, "key must be string")); } #ifndef DOXYGEN @@ -278,7 +269,6 @@ struct Foreach_info { Value *body_code; Value *delim_maybe_code; - Value *var_context; VString *vkey; bool need_delim; }; @@ -289,8 +279,8 @@ static void one_foreach_cycle(const Hash Foreach_info& i=*static_cast(info); i.vkey->set_string(akey); - i.var_context->put_element(*i.key_var_name, i.vkey); - i.var_context->put_element(*i.value_var_name, static_cast(avalue)); + i.r->root->put_element(*i.key_var_name, i.vkey); + i.r->root->put_element(*i.value_var_name, static_cast(avalue)); Value& processed_body=i.r->process(*i.body_code); if(i.delim_maybe_code) { // delimiter set? @@ -314,11 +304,13 @@ static void _foreach(Request& r, const S &body_code, delim_maybe_code, - body_code.get_junction()->wcontext, new(pool) VString(pool), false }; - static_cast(r.self)->hash().for_each(one_foreach_cycle, &info); + VHash& self=*static_cast(r.self); + Hash& hash=self.hash(&method_name); + VHash_lock lock(self); + hash.for_each(one_foreach_cycle, &info); } // constructor