--- parser3/src/main/pa_table.C 2001/01/30 13:43:43 1.7 +++ parser3/src/main/pa_table.C 2001/03/12 12:00:06 1.12 @@ -1,5 +1,9 @@ /* - $Id: pa_table.C,v 1.7 2001/01/30 13:43:43 paf Exp $ + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: pa_table.C,v 1.12 2001/03/12 12:00:06 paf Exp $ */ #include @@ -7,15 +11,14 @@ #include "pa_table.h" #include "pa_pool.h" -Table::Table(Request& arequest, +Table::Table(Pool& apool, char *afile, uint aline, Array *acolumns, int initial_rows) : - Array(arequest.pool(), initial_rows), - request(arequest), + Array(apool, initial_rows), fcurrent(0), fcolumns(acolumns), - name2number(arequest.pool(), false) { + name2number(pool(), false) { #ifndef NO_STRING_ORIGIN forigin.file=afile; forigin.line=aline; @@ -23,15 +26,14 @@ Table::Table(Request& arequest, if(fcolumns) for(int i=0; isize(); i++) { - String name(pool); - name.APPEND(fcolumns->get_cstr(i), 0, 0); + const String& name=*fcolumns->get_string(i); name2number.put(name, i+1); } } const Array &Table::at(int index) { if(index<0 || index>=size()) - request.exception().raise(0, 0, + THROW(0, 0, 0, "table row index %d is out of range [0..%d]", index, size()-1); @@ -39,32 +41,21 @@ const Array &Table::at(int index) { return *static_cast(get(index)); } -const char *Table::item(int index) { - const Array& row=at(fcurrent); - return row.get_cstr(index); -} - -const char *Table::item(const String& column_name) { +const String *Table::item(const String& column_name) { int column_index; - if(fcolumns) { + if(fcolumns) { // named int found_index=name2number.get_int(column_name); if(found_index) column_index=found_index-1; else - request.exception().raise(0, 0, + THROW(0, 0, &column_name, "column not found"); - } else { + } else { // nameless column_index=atoi(column_name.cstr()); const Array& row=at(fcurrent); - if(column_index<0 || column_index>=row.size()) - return 0; - /* - request.exception().raise(0, 0, - &column_name, - "table column index %d is out of range [0..%d]", - column_index, row->size()-1); - */ + if(column_index<0 || column_index>=row.size()) // read past proper index? + return 0; // it's OK, just return nothing } return item(column_index);