--- parser3/src/classes/table.C 2001/04/27 17:17:58 1.65.2.2 +++ parser3/src/classes/table.C 2001/05/08 06:42:54 1.73 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: table.C,v 1.65.2.2 2001/04/27 17:17:58 paf Exp $ + $Id: table.C,v 1.73 2001/05/08 06:42:54 paf Exp $ */ #include "pa_config_includes.h" @@ -19,6 +19,7 @@ #include "pa_vint.h" #include "pa_sql_connection.h" #include "pa_dir.h" +#include "pa_vbool.h" // defines @@ -28,18 +29,18 @@ 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 -void _set(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _set(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); // data is last parameter Value& vdata=params->get_junction(params->size()-1, "body must be code"); @@ -81,7 +82,7 @@ void _set(Methoded& m, Request& r, const static_cast(r.self)->set_table(table); } -void _load(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _load(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); // filename is last parameter Value& vfilename=params->get_no_junction(params->size()-1, @@ -130,7 +131,7 @@ void _load(Methoded& m, Request& r, cons static_cast(r.self)->set_table(table); } -void _save(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _save(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Value& vtable_name=params->get_no_junction(params->size()-1, "file name must not be code"); @@ -177,19 +178,19 @@ void _save(Methoded& m, Request& r, cons sdata.cstr(), sdata.size(), true); } -void _count(Methoded& m, Request& r, const String&, MethodParams *) { +static void _count(Request& r, const String&, MethodParams *) { Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, static_cast(r.self)->table().size()); r.write_no_lang(value); } -void _line(Methoded& m, Request& r, const String& method_name, MethodParams *) { +static void _line(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, 1+static_cast(r.self)->table().current()); r.write_no_lang(value); } -void _offset(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _offset(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Table& table=static_cast(r.self)->table(); if(params->size()) @@ -200,7 +201,7 @@ void _offset(Methoded& m, Request& r, co } } -void _menu(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _menu(Request& r, const String& method_name, MethodParams *params) { Value& body_code=params->get_junction(0, "body must be code"); Value *delim_code=params->size()==2?¶ms->get(1):0; @@ -224,7 +225,7 @@ void _menu(Methoded& m, Request& r, cons table.set_current(saved_current); vtable.unlock(); } -void _empty(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _empty(Request& r, const String& method_name, MethodParams *params) { Table& table=static_cast(r.self)->table(); if(table.size()==0) r.write_pass_lang(r.process(params->get(0))); @@ -241,23 +242,22 @@ 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); ri.hash->put(column_name, value); } -void _record(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _record(Request& r, const String& method_name, MethodParams *params) { 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); } } @@ -284,7 +284,7 @@ static int sort_cmp_double(const void *a else return 0; } -void _sort(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _sort(Request& r, const String& method_name, MethodParams *params) { Value& key_maker=params->get_junction(0, "key-maker must be code"); bool reverse=params->size()==2/*..[asc|desc]*/? @@ -327,22 +327,19 @@ void _sort(Methoded& m, Request& r, cons table.set_current(0); } -void _locate(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +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()); + params->get(1).as_string())); + result.set_name(method_name); + r.write_no_lang(result); } -void _found(Methoded& m, 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"))); -} - -void _flip(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _flip(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); VTable& vtable=*static_cast(r.self); @@ -362,7 +359,7 @@ void _flip(Methoded& m, Request& r, cons vtable.set_table(new_table); } -void _append(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _append(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); // data is last parameter const String& string= @@ -372,10 +369,14 @@ void _append(Methoded& m, Request& r, co Array& row=*new(pool) Array(pool); string.split(row, 0, "\t", 1, String::UL_CLEAN); - static_cast(r.self)->table()+=&row; + VTable& vtable=*static_cast(r.self); + // disable ^a.menu{^a.append[]} + vtable.lock(); + vtable.table()+=&row; + vtable.unlock(); } -void _join(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _join(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Table *maybe_src=params->get_no_junction(0, "table ref must not be code").get_table(); @@ -407,8 +408,7 @@ void _join(Methoded& m, Request& r, cons } } -/// ^table:sql{query}[(count[;offset])] -void _sql(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _sql(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); if(!r.connection) @@ -483,9 +483,7 @@ void _sql(Methoded& m, Request& r, const static_cast(r.self)->set_table(table); } -/// ^table:dir[path] -/// ^table:dir[path][regexp] -void _dir(Methoded& m, Request& r, const String& method_name, MethodParams *params) { +static void _dir(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); Value& relative_path=params->get_no_junction(0, "path must not be code"); @@ -544,7 +542,7 @@ void _dir(Methoded& m, Request& r, const 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); @@ -562,8 +560,8 @@ void _dir(Methoded& m, Request& r, const // constructor -MTable::MTable(Pool& pool) : Methoded(pool) { - set_name(NEW String(pool, TABLE_CLASS_NAME)); +MTable::MTable(Pool& apool) : Methoded(apool) { + set_name(*NEW String(pool(), TABLE_CLASS_NAME)); // ^table:set{data} // ^table:set[nameless]{data} @@ -604,9 +602,6 @@ MTable::MTable(Pool& pool) : Methoded(po // ^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);