--- parser3/src/main/pa_table.C 2003/04/02 08:35:43 1.53.2.10.2.4 +++ parser3/src/main/pa_table.C 2005/08/05 13:03:02 1.60.14.1 @@ -1,17 +1,17 @@ /** @file Parser: table class. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_TABLE_C="$Date: 2003/04/02 08:35:43 $"; +static const char * const IDENT_TABLE_C="$Date: 2005/08/05 13:03:02 $"; #include "pa_table.h" #include "pa_exception.h" -Table::Table(columns_type acolumns, int initial_rows): +Table::Table(columns_type acolumns, size_t initial_rows): Array(initial_rows), fcurrent(0), @@ -19,22 +19,22 @@ Table::Table(columns_type acolumns, int name2number(new name2number_hash_class) { if(fcolumns) { - size_t fcolumns_count=fcolumns->count(); - for(size_t i=0; iget(i); - name2number->put(name, i+1); + size_t number=1; + for(Array_iterator i(*fcolumns); i.has_next(); ) { + const String& name=*i.next(); + name2number->put(name, number++); } } } -Table::Table(const Table& src, int offset, int limit) : - Array(limit/*may be more than needed, no harm done*/), +Table::Table(const Table& src, Action_options& options) : + Array(options.limit==ARRAY_OPTION_LIMIT_ALL?0:options.limit/*may be more than needed, no harm done*/), fcurrent(0), fcolumns(src.fcolumns), name2number(src.name2number) { - append(src, offset, limit); + append(src, options.offset, options.limit, options.reverse); } int Table::column_name2index(const String& column_name, bool bark) const { @@ -52,27 +52,32 @@ int Table::column_name2index(const Strin const String* Table::item(size_t column) { if(valid(fcurrent)) { element_type row=get(fcurrent); - if(column>=0 && columncount()) // proper index? + if(columncount()) // proper index? return row->get(column); } return 0; // it's OK we don't have row|column, just return nothing } -bool Table::locate(size_t column, const String& value) { - size_t scurrent=fcurrent; - size_t lcount=count(); - for(fcurrent=0; fcurrentcolumn); + return item_value && *item_value==*info->value; +} + +bool Table::locate(int column, const String& value, + Table::Action_options& options) { + Locate_int_string_info info={column, &value}; + return table_first_that(locate_int_string, &info, options); +} + +bool Table::locate(const String& column, const String& value, + Table::Action_options& options) { + return locate(column_name2index(column, true), value, options); } void Table::offset(bool absolute, int offset) {