--- parser3/src/classes/hash.C 2001/05/21 16:38:46 1.3 +++ parser3/src/classes/hash.C 2001/07/02 13:59:59 1.9 @@ -5,14 +5,16 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: hash.C,v 1.3 2001/05/21 16:38:46 parser Exp $ + $Id: hash.C,v 1.9 2001/07/02 13:59:59 parser Exp $ */ +static const char *RCSId="$Id: hash.C,v 1.9 2001/07/02 13:59:59 parser Exp $"; #include "classes.h" #include "pa_request.h" #include "pa_vhash.h" -#include "pa_vunknown.h" +#include "pa_vvoid.h" #include "pa_sql_connection.h" +#include "pa_vtable.h" // defines @@ -40,7 +42,7 @@ static void _default(Request& r, const S vhash.set_default(params->get(0)); // info: may be code.. else { Value *default_value=vhash.get_default(); - r.write_assign_lang(default_value?*default_value:*new(pool) VUnknown(pool)); + r.write_assign_lang(default_value?*default_value:*new(pool) VVoid(pool)); } } @@ -124,6 +126,28 @@ static void _sql(Request& r, const Strin } } +static void keys_collector(const Hash::Key& key, Hash::Val *value, void *info) { + Table& table=*static_cast(info); + Pool& pool=table.pool(); + + Array& row=*new(pool) Array(pool); + row+=&key; + table+=&row; +} +static void _keys(Request& r, const String& method_name, MethodParams *) { + Pool& pool=r.pool(); + + Array& columns=*new(pool) Array(pool); + 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); + + VTable& result=*new(pool) VTable(pool, &table); + result.set_name(method_name); + r.write_no_lang(result); +} + // constructor MHash::MHash(Pool& apool) : Methoded(apool) { @@ -136,6 +160,8 @@ MHash::MHash(Pool& apool) : Methoded(apo // ^hash:sql[query][(count[;offset])] add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 3); + // ^hash.keys[] + add_native_method("keys", Method::CT_DYNAMIC, _keys, 0, 0); } // global variable