--- parser3/src/main/pa_table.C 2001/05/07 08:29:45 1.27 +++ parser3/src/main/pa_table.C 2002/08/01 11:26:51 1.48 @@ -1,14 +1,13 @@ /** @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.27 2001/05/07 08:29:45 paf Exp $ + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ -#include +static const char* IDENT_TABLE_C="$Id: pa_table.C,v 1.48 2002/08/01 11:26:51 paf Exp $"; + +//#include #include "pa_table.h" #include "pa_pool.h" @@ -16,14 +15,14 @@ Table::Table(Pool& apool, const String *aorigin_string, - Array *acolumns, + const Array *acolumns, int initial_rows) : Array(apool, initial_rows), forigin_string(aorigin_string), fcurrent(0), fcolumns(acolumns), - name2number(pool()) { + name2number(*NEW Hash(pool())) { if(fcolumns) for(int i=0; isize(); i++) { @@ -32,16 +31,46 @@ Table::Table(Pool& apool, } } -int Table::column_name2index(const String& column_name) const { - if(fcolumns) // named - return name2number.get_int(column_name)-1; // -1 = column not found - else { // nameless - char *error_pos=0; - int result=(int)strtol(column_name.cstr(), &error_pos, 0); - if(error_pos && *error_pos) - THROW(0, 0, +Table::Table(const Table& source) : + Array(source), + + forigin_string(source.forigin_string), + fcurrent(source.fcurrent), + fcolumns(source.fcolumns), + name2number(source.name2number) { + +} + +Table::Table(Pool& apool, const Table& source, int offset) : + Array(apool), + + forigin_string(source.forigin_string), + fcurrent(source.fcurrent), + fcolumns(source.fcolumns), + name2number(source.name2number) { + + append_array(source, offset); +} + +int Table::column_name2index(const String& column_name, bool bark) const { + if(fcolumns) {// named + int result=name2number.get_int(column_name)-1; // -1 = column not found + if(bark && result<0) + throw Exception("parser.runtime", &column_name, - "invalid column number"); + "column not found"); + return result; + } else { // nameless + char *error_pos; + const char *cstr=column_name.cstr(); + int result=(int)strtol(cstr, &error_pos, 0); + if(*error_pos/*not EOS*/) { + result=-1; + if(bark) + throw Exception("parser.runtime", + &column_name, + "invalid column number"); + } return result; } } @@ -56,17 +85,22 @@ const String *Table::item(int column) co } bool Table::locate(int column, const String& value) { + int scurrent=fcurrent; for(fcurrent=0; fcurrent