|
|
| version 1.29, 2001/05/08 08:14:56 | version 1.49, 2002/08/01 11:41:19 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: table class. | Parser: table class. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | |
| */ | */ |
| #include <stdlib.h> | static const char* IDENT_TABLE_C="$Date$"; |
| //#include <stdlib.h> | |
| #include "pa_table.h" | #include "pa_table.h" |
| #include "pa_pool.h" | #include "pa_pool.h" |
| Line 16 | Line 15 |
| Table::Table(Pool& apool, | Table::Table(Pool& apool, |
| const String *aorigin_string, | const String *aorigin_string, |
| Array *acolumns, | const Array *acolumns, |
| int initial_rows) : | int initial_rows) : |
| Array(apool, initial_rows), | Array(apool, initial_rows), |
| forigin_string(aorigin_string), | forigin_string(aorigin_string), |
| fcurrent(0), | fcurrent(0), |
| fcolumns(acolumns), | fcolumns(acolumns), |
| name2number(pool()) { | name2number(*NEW Hash(pool())) { |
| if(fcolumns) | if(fcolumns) |
| for(int i=0; i<fcolumns->size(); i++) { | for(int i=0; i<fcolumns->size(); i++) { |
| Line 32 Table::Table(Pool& apool, | Line 31 Table::Table(Pool& apool, |
| } | } |
| } | } |
| 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 { | int Table::column_name2index(const String& column_name, bool bark) const { |
| if(fcolumns) {// named | if(fcolumns) {// named |
| int result=name2number.get_int(column_name)-1; // -1 = column not found | int result=name2number.get_int(column_name)-1; // -1 = column not found |
| if(bark && result<0) | if(bark && result<0) |
| THROW(0, 0, | throw Exception("parser.runtime", |
| &column_name, | &column_name, |
| "column not found"); | "column not found"); |
| return result; | return result; |
| } else { // nameless | } else { // nameless |
| char *error_pos=0; | char *error_pos; |
| int result=(int)strtol(column_name.cstr(), &error_pos, 0); | const char *cstr=column_name.cstr(); |
| if(error_pos && *error_pos) | int result=(int)strtol(cstr, &error_pos, 0); |
| THROW(0, 0, | if(*error_pos/*not EOS*/) { |
| &column_name, | result=-1; |
| "invalid column number"); | if(bark) |
| throw Exception("parser.runtime", | |
| &column_name, | |
| "invalid column number"); | |
| } | |
| return result; | return result; |
| } | } |
| } | } |
| Line 61 const String *Table::item(int column) co | Line 85 const String *Table::item(int column) co |
| } | } |
| bool Table::locate(int column, const String& value) { | bool Table::locate(int column, const String& value) { |
| int scurrent=fcurrent; | |
| for(fcurrent=0; fcurrent<size(); fcurrent++) { | for(fcurrent=0; fcurrent<size(); fcurrent++) { |
| const String *item_value=item(column); | const String *item_value=item(column); |
| if(item_value && *item_value==value) | if(item_value && *item_value==value) |
| return true; | return true; |
| } | } |
| fcurrent=0; | fcurrent=scurrent; |
| return false; | return false; |
| } | } |
| Line 75 bool Table::locate(const String& column, | Line 100 bool Table::locate(const String& column, |
| return locate(column_name2index(column, true), value); | return locate(column_name2index(column, true), value); |
| } | } |
| void Table::shift(int offset) { | void Table::offset(bool absolute, int offset) { |
| if(size()) | if(size()) |
| fcurrent=(fcurrent+offset+size())%size(); | fcurrent=((absolute?0:fcurrent)+offset+size())%size(); |
| } | } |