--- parser3/src/main/pa_table.C 2001/01/29 21:51:52 1.4 +++ parser3/src/main/pa_table.C 2001/03/25 08:52:36 1.17 @@ -1,5 +1,11 @@ -/* - $Id: pa_table.C,v 1.4 2001/01/29 21:51:52 paf Exp $ +/** @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.17 2001/03/25 08:52:36 paf Exp $ */ #include @@ -7,57 +13,43 @@ #include "pa_table.h" #include "pa_pool.h" -Table::Table(Request& arequest, - char *afile, uint aline, +Table::Table(Pool& apool, Array *acolumns, int initial_rows) : - Array(arequest.pool, initial_rows), - request(arequest), - current(0), - columns(acolumns), - name2number(arequest.pool, false) { -#ifndef NO_STRING_ORIGIN - origin.file=afile; - origin.line=aline; -#endif - - if(columns) - for(int i=0; isize(); i++) { - String name(pool); - name.APPEND(columns->get_cstr(i), 0, 0); + Array(apool, initial_rows), + + fcurrent(0), + fcolumns(acolumns), + name2number(pool(), false) { + + if(fcolumns) + for(int i=0; isize(); i++) { + const String& name=*fcolumns->get_string(i); name2number.put(name, i+1); } } -const Array *Table::at(int index) { - if(index<0 || index>=size()) - request.operator_error.raise(0, - "table column index %d is out of range [0..%d]", - index, size()-1); - - return static_cast(get(index)); -} - -const char *Table::item(int index) { - const Array *row=at(current); - return row->get_cstr(index); +const Array &Table::at(int index) { + return *const_cast(static_cast(get(index))); } -const char *Table::item(String& column_name) { +const String *Table::item(const String& column_name) { int column_index; - if(columns) { + if(fcolumns) { // named int found_index=name2number.get_int(column_name); if(found_index) column_index=found_index-1; else - request.operator_error.raise(&column_name, "column not found"); - } else { + THROW(0, 0, + &column_name, + "column not found"); + } else { // nameless column_index=atoi(column_name.cstr()); - const Array *row=at(current); - if(column_index<0 || column_index>=row->size()) - request.operator_error.raise(&column_name, - "table column index %d is out of range [0..%d]", - column_index, row->size()-1); + if(!valid(fcurrent)) + return 0; // it's OK we don't have row, just return nothing + 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 } return item(column_index);