--- parser3/src/main/pa_table.C 2001/03/26 10:36:56 1.19 +++ parser3/src/main/pa_table.C 2001/03/28 09:01:22 1.22 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_table.C,v 1.19 2001/03/26 10:36:56 paf Exp $ + $Id: pa_table.C,v 1.22 2001/03/28 09:01:22 paf Exp $ */ #include @@ -31,69 +31,43 @@ Table::Table(Pool& apool, } } -const Array &Table::at(int index) { - return *const_cast(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 && columnsize(); column++) { - if(column) - sdata.APPEND_CONST("\t"); - sdata.append(*static_cast(fcolumns->quick_get(column)), - String::UL_TABLE); - } - } else { // nameless table - int lsize=size()?static_cast(get(0))->size():0; - if(lsize) - for(int column=0; column(quick_get(index)); - for(int column=0; columnsize(); column++) { - if(column) - sdata.APPEND_CONST("\t"); - sdata.append(*static_cast(row->quick_get(column)), - String::UL_TABLE); - } - sdata.APPEND_CONST("\n"); +bool Table::locate(const String& column, const String& value) { + int key_index=column_name2index(column); + for(fcurrent=0; fcurrent