--- parser3/src/classes/table.C 2001/04/28 13:49:14 1.67 +++ parser3/src/classes/table.C 2001/05/08 06:42:54 1.73 @@ -5,20 +5,21 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: table.C,v 1.67 2001/04/28 13:49:14 paf Exp $ + $Id: table.C,v 1.73 2001/05/08 06:42:54 paf Exp $ */ #include "pa_config_includes.h" #include "pcre.h" -#include "pa_methoded.h" +#include "classes.h" #include "pa_common.h" #include "pa_request.h" #include "pa_vtable.h" #include "pa_vint.h" #include "pa_sql_connection.h" #include "pa_dir.h" +#include "pa_vbool.h" // defines @@ -28,13 +29,13 @@ class MTable : public Methoded { public: // VStateless_class - Value *create_new_value(Pool& pool) { return new(pool) VTable(pool); } public: MTable(Pool& pool); - bool used_directly() { return true; } +public: // Methoded + bool used_directly() { return true; } }; // methods @@ -241,9 +242,8 @@ struct Record_info { static void store_column_item_to_hash(Array::Item *item, void *info) { Record_info& ri=*static_cast(info); String& column_name=*static_cast(item); - const String *column_item=ri.table->item(column_name); Value *value; - if(column_item) + if(const String *column_item=ri.table->item(column_name)) value=new(*ri.pool) VString(*column_item); else value=new(*ri.pool) VUnknown(*ri.pool); @@ -253,11 +253,11 @@ static void _record(Request& r, const St Table& table=static_cast(r.self)->table(); if(const Array *columns=table.columns()) { Pool& pool=r.pool(); - Value& value=*new(pool) VHash(pool); - Record_info record_info={&pool, &table, value.get_hash()}; + Value& result=*new(pool) VHash(pool); + Record_info record_info={&pool, &table, result.get_hash()}; columns->for_each(store_column_item_to_hash, &record_info); - - r.write_no_lang(value); + result.set_name(method_name); + r.write_no_lang(result); } } @@ -328,18 +328,15 @@ static void _sort(Request& r, const Stri } static void _locate(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + VTable& vtable=*static_cast(r.self); Table& table=vtable.table(); - vtable.last_locate_was_successful=table.locate( + Value& result=*new(pool) VBool(pool, table.locate( params->get(0).as_string(), - params->get(1).as_string()); -} - -static void _found(Request& r, const String& method_name, MethodParams *params) { - if(static_cast(r.self)->last_locate_was_successful) - r.write_pass_lang(r.process(params->get_junction(0, "found-parameter must be code"))); - else if(params->size()==2) - r.write_pass_lang(r.process(params->get_junction(0, "else-parameter must be code"))); + params->get(1).as_string())); + result.set_name(method_name); + r.write_no_lang(result); } static void _flip(Request& r, const String& method_name, MethodParams *params) { @@ -411,7 +408,6 @@ static void _join(Request& r, const Stri } } -/// ^table:sql{query}[(count[;offset])] static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -487,8 +483,6 @@ static void _sql(Request& r, const Strin static_cast(r.self)->set_table(table); } -/// ^table:dir[path] -/// ^table:dir[path][regexp] static void _dir(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -548,7 +542,7 @@ static void _dir(Request& r, const Strin char *file_name_cstr=(char *)r.malloc(file_name_size); memcpy(file_name_cstr, ffblk.ff_name, file_name_size); String &file_name=*new(pool) String(pool); - file_name.APPEND_TAINTED(file_name_cstr, file_name_size, + file_name.APPEND(file_name_cstr, file_name_size, String::UL_FILE_NAME, method_name.origin().file, method_name.origin().line); Array& row=*new(pool) Array(pool); @@ -608,9 +602,6 @@ MTable::MTable(Pool& apool) : Methoded(a // ^table.locate[field;value] add_native_method("locate", Method::CT_DYNAMIC, _locate, 2, 2); - // ^table.found{when-found} - // ^table.found{when-found}{when-not-found} - add_native_method("found", Method::CT_DYNAMIC, _found, 1, 2); // ^table.flip[] add_native_method("flip", Method::CT_DYNAMIC, _flip, 0, 0);