--- parser3/src/classes/table.C 2003/04/11 16:05:43 1.172.2.14.2.30 +++ parser3/src/classes/table.C 2003/09/29 11:03:21 1.185 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_TABLE_C="$Date: 2003/04/11 16:05:43 $"; +static const char* IDENT_TABLE_C="$Date: 2003/09/29 11:03:21 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -58,12 +58,22 @@ static Table::Action_options get_action_ if(!params.count()) return result; + Value& maybe_options=params.last(); +/* can not do it: + want to enable ^table::create[$source; +# $.option[] + ] + but there is ^table.locate[name;value] - HashStringValue* options=params.last().get_hash(); + if(maybe_options.is_string()) { // allow empty options + result.defined=true; + return result; + } +*/ + HashStringValue* options=maybe_options.get_hash(); if(!options) return result; - result.defined=true; bool defined_offset=false; @@ -100,7 +110,7 @@ static Table::Action_options get_action_ return result; } -static check_option_param(bool options_defined, +static void check_option_param(bool options_defined, MethodParams& params, size_t next_param_index, const char *msg) { if(next_param_index+(options_defined?1:0) != params.count()) @@ -197,8 +207,9 @@ static void _load(Request& r, MethodPara } // parse cells - Table& table=*new Table(columns); + Table& table=*new Table(columns);//что-то очень плохое с realloc'ом: 1000 сильно помогает char *row_chars; + int cells=0; while(row_chars=getrow(&data)) { // remove empty&comment lines if(!*row_chars || *row_chars == '#') @@ -206,6 +217,7 @@ static void _load(Request& r, MethodPara Table::element_type row(new ArrayString); while(char *cell_chars=lsplit(&row_chars, '\t')) { *row+=new String(cell_chars, 0, true); + cells++; } table+=row; }; @@ -235,8 +247,9 @@ static void _save(Request& r, MethodPara for(int column=0; columnget_table(); else { // no? creating table of same structure as source - Table::Action_options table_options; + Table::Action_options table_options(0, 0); table=new Table(*info->table, table_options/*no rows, just structure*/); info->hash->put(*key, new VTable(table)); } @@ -460,7 +473,7 @@ static void _hash(Request& r, MethodPara { - Row_info info; + Row_info info={0}; info.r=&r; info.table=&self_table; Value* key_param=¶ms[0]; @@ -549,13 +562,13 @@ static void _sort(Request& r, MethodPara } #ifndef DOXYGEN -struct Locate_expression_func_info { +struct Expression_is_true_info { Request* r; Value* expression_code; }; #endif -bool locate_expression_func(Table& self, void* ainfo) { - Locate_expression_func_info& info=*static_cast(ainfo); +static bool expression_is_true(Table& self, void* ainfo) { + Expression_is_true_info& info=*static_cast(ainfo); return info.r->process_to_value(*info.expression_code).as_bool(); } static bool _locate_expression(Table& table, Table::Action_options o, @@ -564,8 +577,8 @@ static bool _locate_expression(Table& ta "locate by expression only has parameters: expression and, maybe, options"); Value& expression_code=params.as_junction(0, "must be expression"); - Locate_expression_func_info info={&r, &expression_code}; - return table.locate(locate_expression_func, &info, o); + Expression_is_true_info info={&r, &expression_code}; + return table.table_first_that(expression_is_true, &info, o); } static bool _locate_name_value(Table& table, Table::Action_options o, Request& r, MethodParams& params) { @@ -589,7 +602,7 @@ static void _locate(Request& r, MethodPa static void _flip(Request& r, MethodParams& params) { Table& old_table=GET_SELF(r, VTable).table(); - Table& new_table=*new Table(old_table.columns()); + Table& new_table=*new Table(0); if(size_t old_count=old_table.count()) if(size_t old_cols=old_table[0]->count()) for(size_t column=0; columncolumns(); + size_t dest_columns_count=dest_columns->count(); + Table::element_type dest_row(new ArrayString(dest_columns_count)); + for(size_t dest_column=0; dest_columnget(dest_column)); + *dest_row+=src_item?src_item:new String; + } + *dest+=dest_row; +} +static void join_nameless_row(Table& src, Table* dest) { + *dest+=src[src.current()]; +} static void _join(Request& r, MethodParams& params) { Table* maybe_src=params.as_no_junction(0, "table ref must not be code").get_table(); if(!maybe_src) @@ -635,27 +661,10 @@ static void _join(Request& r, MethodPara 0, "source and destination are same table"); - if(Table::columns_type dest_columns=dest.columns()) { // dest is named - size_t saved_src_current=src.current(); - size_t m=src.count()-o.offset; - if(!o.limit || o.limit>m) - o.limit=m; - int end=o.offset+o.limit; - for(int src_row=o.offset; src_rowcount(); dest_column++) { - const String* src_item=src.item(*dest_columns->get(dest_column)); - *dest_row+=src_item?src_item:new String; - } - dest+=dest_row; - } - src.set_current(saved_src_current); - } else { // dest is nameless - size_t src_count=src.count(); - for(size_t src_row=0; src_row