--- parser3/src/main/pa_table.C 2001/03/12 13:37:48 1.13.2.1 +++ parser3/src/main/pa_table.C 2001/04/04 10:50:36 1.25 @@ -1,21 +1,26 @@ -/* - 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.2.1 2001/03/12 13:37:48 paf Exp $ + $Id: pa_table.C,v 1.25 2001/04/04 10:50:36 paf Exp $ */ #include #include "pa_table.h" #include "pa_pool.h" +#include "pa_exception.h" Table::Table(Pool& apool, + const String *aorigin_string, Array *acolumns, int initial_rows) : Array(apool, initial_rows), + forigin_string(aorigin_string), fcurrent(0), fcolumns(acolumns), name2number(pool(), false) { @@ -27,28 +32,49 @@ Table::Table(Pool& apool, } } -const Array &Table::at(int index) { - return *static_cast(get(index)); -} - -const char *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"); + return 0; // unreached + } } else { // nameless - column_index=atoi(column_name.cstr()); - if(!valid(fcurrent)) - return 0; // it's OK we don't have row, just return nothing + char *error_pos=0; + int result=(int)strtol(column_name.cstr(), &error_pos, 0); + if(error_pos && *error_pos) + THROW(0, 0, + &column_name, + "invalid column number"); + return result; + } +} + +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