--- parser3/src/classes/table.C 2003/11/04 12:04:39 1.188 +++ parser3/src/classes/table.C 2004/04/01 15:08:48 1.201 @@ -1,11 +1,11 @@ /** @file Parser: @b table parser class. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_TABLE_C="$Date: 2003/11/04 12:04:39 $"; +static const char * const IDENT_TABLE_C="$Date: 2004/04/01 15:08:48 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -21,7 +21,7 @@ static const char* IDENT_TABLE_C="$Date: class MTable: public Methoded { public: // VStateless_class - Value* create_new_value() { return new VTable(); } + Value* create_new_value(Pool&) { return new VTable(); } public: MTable(); @@ -178,34 +178,6 @@ static void _create(Request& r, MethodPa GET_SELF(r, VTable).set_table(table); } -static char* remove_encloser(char* cstr, char encloser) { - if(cstr[0]!=encloser) - return cstr; - - size_t length=strlen(cstr); - if(length<2 || cstr[length-1]!=encloser) - return cstr; - - // 'string' - - cstr[length-1]=0; - cstr++; - - // double-encloser stands for encloser - char *read; - char *write; - write=read=cstr; - while(char c=*read++) { - if(c==encloser && *read==encloser) - read++; - - *write++=c; - } - *write=0; // terminate - - return cstr; -} - struct lsplit_result { char* piece; char delim; @@ -249,7 +221,7 @@ static lsplit_result lsplit(char** strin char *write; write=read=string; char c; - while(c=*read++) { + while((c=*read++)) { if(c==encloser) { char n=*read; if(n==encloser) // double-encloser stands for encloser @@ -279,7 +251,8 @@ static void skip_empty_and_comment_lines while( char c=*data ) { if( c== '\n' || c == '#' ) { /*nowhere=*/getrow(&data); // remove empty&comment lines - *data_ref=data; + if(!(*data_ref=data)) + break; continue; } break; @@ -363,7 +336,7 @@ static void _load(Request& r, MethodPara Table::element_type row(new ArrayString); skip_empty_and_comment_lines(&data); while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) { - if(!sr.delim && !row->count()) // append last empty column [if without \n] + if(!*sr.piece && !sr.delim && !row->count()) // append last empty column [if without \n] break; *row+=new String(sr.piece, 0, true); if(sr.delim=='\n') { @@ -384,10 +357,10 @@ static void maybe_enclose( String& to, c if(encloser) { to<<*sencloser; // while we have 'encloser'... - for( size_t pos_before, pos_after=0; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; ) { + size_t pos_after=0; + for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before+1) { to<get_junction()?key_param:0; - info.key_field=info.key_code?-1 - :self_table.column_name2index(key_param->as_string(), true); - info.value_fields=&value_fields; - info.hash=&result.hash(); - info.distinct=distinct; - info.row=0; + Row_info info={ + &r, + &self_table, + /*key_code=*/key_param->get_junction()?key_param:0, + /*key_field=*/0/*filled below*/, + &value_fields, + &result.hash(), + distinct, + /*row=*/0 + }; + info.key_field=(info.key_code?-1 + :self_table.column_name2index(key_param->as_string(), true)); int saved_current=self_table.current(); self_table.for_each(table_row_to_hash, &info); @@ -761,9 +736,8 @@ struct Expression_is_true_info { Value* expression_code; }; #endif -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 expression_is_true(Table&, Expression_is_true_info* info) { + return info->r->process_to_value(*info->expression_code).as_bool(); } static bool _locate_expression(Table& table, Table::Action_options o, Request& r, MethodParams& params) { @@ -775,7 +749,7 @@ static bool _locate_expression(Table& ta 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) { + Request&, MethodParams& params) { check_option_param(o.defined, params, 2, "locate by locate by name has parameters: name, value and, maybe, options"); const String& name=params.as_string(0, "column name must be string"); @@ -794,7 +768,7 @@ static void _locate(Request& r, MethodPa } -static void _flip(Request& r, MethodParams& params) { +static void _flip(Request& r, MethodParams&) { Table& old_table=GET_SELF(r, VTable).table(); Table& new_table=*new Table(0); if(size_t old_count=old_table.count()) @@ -855,7 +829,7 @@ static void _join(Request& r, MethodPara 0, "source and destination are same table"); - if(Table::columns_type dest_columns=dest.columns()) // dest is named + if(dest.columns()) // dest is named src.table_for_each(join_named_row, &dest, o); else // dest is nameless src.table_for_each(join_nameless_row, &dest, o); @@ -1005,7 +979,6 @@ static void _select(Request& r, MethodPa source_table.set_current(row); bool condition=r.process_to_value(vcondition, - /*0/*no name* /,*/ false/*don't intercept string*/).as_bool(); if(condition) // ...condition is true=