--- parser3/src/classes/table.C 2001/03/29 20:53:02 1.39 +++ parser3/src/classes/table.C 2001/04/02 15:59:06 1.43 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: table.C,v 1.39 2001/03/29 20:53:02 paf Exp $ + $Id: table.C,v 1.43 2001/04/02 15:59:06 paf Exp $ */ #include "pa_config_includes.h" @@ -20,16 +20,11 @@ VStateless_class *table_class; // methods - +/// @test remove CONFIG untaint, make pos() searches in String static void set_or_load( Request& r, const String& method_name, Array *params, bool is_load) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Pool& pool=r.pool(); // data is last parameter Value *vdata_or_filename=static_cast(params->get(params->size()-1)); @@ -92,22 +87,14 @@ static void set_or_load( // replace any previous table value static_cast(r.self)->set_table(table); } - - static void _set(Request& r, const String& method_name, Array *params) { set_or_load(r, method_name, params, false); } - static void _load(Request& r, const String& method_name, Array *params) { set_or_load(r, method_name, params, true); } static void _save(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Pool& pool=r.pool(); Value *vtable_name=static_cast(params->get(params->size()-1)); // forcing @@ -162,33 +149,18 @@ static void _save(Request& r, const Stri } static void _count(Request& r, const String&method_name, Array *) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, static_cast(r.self)->table().size()); r.write_no_lang(value); } static void _line(Request& r, const String& method_name, Array *) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Pool& pool=r.pool(); Value& value=*new(pool) VInt(pool, 1+static_cast(r.self)->table().current()); r.write_no_lang(value); } static void _offset(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Pool& pool=r.pool(); Table& table=static_cast(r.self)->table(); if(params->size()) @@ -200,11 +172,6 @@ static void _offset(Request& r, const St } static void _menu(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Value& body_code=*static_cast(params->get(0)); // forcing ^menu{this param type} r.fail_if_junction_(false, body_code, @@ -231,11 +198,6 @@ static void _menu(Request& r, const Stri } static void _empty(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Table& table=static_cast(r.self)->table(); if(table.size()==0) { Value& value=r.process(*static_cast(params->get(0))); @@ -263,11 +225,6 @@ static void store_column_item_to_hash(Ar ri.hash->put(column_name, value); } static void _record(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Table& table=static_cast(r.self)->table(); if(const Array *columns=table.columns()) { Pool& pool=r.pool(); @@ -303,11 +260,6 @@ static int sort_cmp_double(const void *a return 0; } static void _sort(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - Value& key_maker=*(Value *)params->get(0); // forcing ^sort{this} ^sort(or this) param type r.fail_if_junction_(false, key_maker, method_name, "key-maker must be junction"); @@ -358,11 +310,6 @@ static void _sort(Request& r, const Stri } static void _locate(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - VTable& vtable=*static_cast(r.self); Table& table=vtable.table(); vtable.last_locate_was_successful=table.locate( @@ -371,11 +318,6 @@ static void _locate(Request& r, const St } static void _found(Request& r, const String& method_name, Array *params) { - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - if(static_cast(r.self)->last_locate_was_successful) { Value& then_code=*static_cast(params->get(0)); // forcing ^found{this param type} @@ -393,12 +335,6 @@ static void _found(Request& r, const Str static void _flip(Request& r, const String& method_name, Array *params) { Pool& pool=r.pool(); - - if(r.self==table_class) - RTHROW(0, 0, - &method_name, - "method of 'table' is not static"); - VTable& vtable=*static_cast(r.self); Table& old_table=*vtable.get_table(); @@ -417,52 +353,119 @@ static void _flip(Request& r, const Stri vtable.set_table(new_table); } +/// @test require \t to be clean [UL_NO] +static void _append(Request& r, const String& method_name, Array *params) { + Pool& pool=r.pool(); + // data is last parameter + Value *value=static_cast(params->get(0)); + // forcing [this body type] + r.fail_if_junction_(true, *value, method_name, "body must not be junction"); + + const String& string=static_cast(value)->as_string(); + + // parse cells + Array& row=*new(pool) Array(pool); + size_t pos_after=0; + int pos_before; + while((pos_before=string.pos("\t", pos_after))>=0) { + row+=&string.piece(pos_after, pos_before); + pos_after=pos_before+1/*\t*/; + } + // last piece + if(pos_after(r.self)->table()+=&row; +} + +static void _join(Request& r, const String& method_name, Array *params) { + Pool& pool=r.pool(); + + Value *value=static_cast(params->get(0)); + // forcing [this table ref type] + r.fail_if_junction_(true, *value, method_name, "table ref must not be junction"); + + Table *maybe_src=value->get_table(); + if(!maybe_src) + RTHROW(0, 0, + &method_name, + "source is not a table"); + + Table& src=*maybe_src; + Table& dest=static_cast(r.self)->table(); + if(&src == &dest) + RTHROW(0, 0, + &method_name, + "source and destination are same table"); + + if(const Array *dest_columns=dest.columns()) { // dest is named + int saved_src_current=src.current(); + for(int src_row=0; src_rowsize(); dest_column++) + dest_row+=src.item(*dest_columns->get_string(dest_column)); + dest+=&dest_row; + } + src.set_current(saved_src_current); + } else { // dest is nameless + for(int src_row=0; src_row