--- parser3/src/main/pa_table.C 2001/03/12 13:13:21 1.13 +++ parser3/src/main/pa_table.C 2001/03/28 09:01:22 1.22 @@ -1,9 +1,11 @@ -/* - Parser +/** @file + Parser: table class. + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_table.C,v 1.13 2001/03/12 13:13:21 paf Exp $ + $Id: pa_table.C,v 1.22 2001/03/28 09:01:22 paf Exp $ */ #include @@ -12,12 +14,12 @@ #include "pa_pool.h" Table::Table(Pool& apool, - const String& asource, + const String *aorigin_string, Array *acolumns, int initial_rows) : Array(apool, initial_rows), - fsource(asource), + forigin_string(aorigin_string), fcurrent(0), fcolumns(acolumns), name2number(pool(), false) { @@ -29,28 +31,43 @@ Table::Table(Pool& apool, } } -const Array &Table::at(int index) { - return *static_cast(get(index)); -} - -const String *Table::item(const String& column_name) { - int column_index; +int Table::column_name2index(const String& column_name) const { if(fcolumns) { // named - int found_index=name2number.get_int(column_name); - if(found_index) - column_index=found_index-1; - else + int column_number=name2number.get_int(column_name); + if(column_number) + return column_number-1; + else { THROW(0, 0, &column_name, "column not found"); - } else { // nameless - column_index=atoi(column_name.cstr()); - if(!valid(fcurrent)) - return 0; // it's OK we don't have row, just return nothing + return 0; // unreached + } + } else // nameless + return atoi(column_name.cstr()); +} + +const String *Table::item(int column) const { + if(valid(fcurrent)) { const Array& row=at(fcurrent); - if(column_index<0 || column_index>=row.size()) // read past proper index? - return 0; // it's OK we don't have column, just return nothing + if(column>=0 && column