--- parser3/src/classes/hash.C 2001/09/17 14:46:49 1.16 +++ parser3/src/classes/hash.C 2001/10/11 11:52:55 1.20 @@ -2,12 +2,10 @@ Parser: @b hash parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - $Id: hash.C,v 1.16 2001/09/17 14:46:49 parser Exp $ + $Id: hash.C,v 1.20 2001/10/11 11:52:55 parser Exp $ */ -static const char *RCSId="$Id: hash.C,v 1.16 2001/09/17 14:46:49 parser Exp $"; #include "classes.h" #include "pa_request.h" @@ -15,7 +13,6 @@ static const char *RCSId="$Id: hash.C,v #include "pa_vvoid.h" #include "pa_sql_connection.h" #include "pa_vtable.h" -#include "pa_vint.h" // defines @@ -92,6 +89,25 @@ private: }; #endif +static void copy_pair_to(const Hash::Key& key, Hash::Val *value, void *info) { + Hash& dest=*static_cast(info); + dest.put(key, value); +} + +static void _create(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + if(params->size()) { + Value& vsrc=params->as_no_junction(0, "copy_from must be hash"); + if(Hash *src=vsrc.get_hash()) + src->for_each(copy_pair_to, &static_cast(r.self)->hash()); + else + PTHROW(0, 0, + &method_name, + "copy_from must be hash"); + } +} + static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -173,6 +189,9 @@ static void _count(Request& r, const Str MHash::MHash(Pool& apool) : Methoded(apool) { set_name(*NEW String(pool(), HASH_CLASS_NAME)); + // ^hash::create[[default value]] + add_native_method("create", Method::CT_DYNAMIC, _create, 0, 1); + // ^hash:sql[query][(count[;offset])] add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 3);