--- parser3/src/main/pa_table.C 2015/07/28 14:42:44 1.65 +++ parser3/src/main/pa_table.C 2020/12/25 22:05:31 1.72 @@ -1,24 +1,23 @@ /** @file Parser: table class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #include "pa_table.h" -volatile const char * IDENT_PA_TABLE_C="$Id: pa_table.C,v 1.65 2015/07/28 14:42:44 moko Exp $" IDENT_PA_TABLE_H; +volatile const char * IDENT_PA_TABLE_C="$Id: pa_table.C,v 1.72 2020/12/25 22:05:31 moko Exp $" IDENT_PA_TABLE_H; #include "pa_exception.h" -Table::Table(columns_type acolumns, size_t initial_rows): - Array(initial_rows), - - fcurrent(0), - fcolumns(acolumns), - name2number(new name2number_hash_class) { +Table::Table(columns_type acolumns, size_t initial_rows): Array(initial_rows), fcurrent(0), fcolumns(acolumns), name2number(NULL){ + column_names_init(); +} - if(fcolumns) { +void Table::column_names_init(){ + if(fcolumns){ + name2number = new name2number_hash_class; size_t number=1; for(Array_iterator i(*fcolumns); i.has_next(); ) { const String& name=*i.next(); @@ -44,13 +43,21 @@ Table::Table(const Table& src, Action_op ((Table &)src).table_for_each(append_row, this, options); } +size_t Table::max_cells() const { + size_t result=0; + for(size_t i=0; icount()>result) + result=row->count(); + } + return result; +} + int Table::column_name2index(const String& column_name, bool bark) const { if(fcolumns) {// named int result=name2number->get(column_name)-1; // -1 = column not found if(bark && result<0) - throw Exception(PARSER_RUNTIME, - &column_name, - "column not found"); + throw Exception(PARSER_RUNTIME, &column_name, "column not found"); return result; } else // nameless return column_name.as_int(); @@ -76,6 +83,16 @@ void Table::put_item(size_t column, cons row->put(column, value); } +void Table::remove_current(){ + if(!valid(fcurrent)) { + throw Exception(PARSER_RUNTIME, 0, "invalid current row"); + } + remove(fcurrent); + if(fcurrent==count() && count()>0){ + fcurrent--; + } +} + #ifndef DOXYGEN struct Locate_int_string_info { int column; @@ -87,14 +104,12 @@ bool locate_int_string(Table& self, Loca return item_value && *item_value==*info->value; } -bool Table::locate(int column, const String& value, - Table::Action_options& options) { +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) { +bool Table::locate(const String& column, const String& value, Table::Action_options& options) { return locate(column_name2index(column, true), value, options); }