Annotation of parser3/src/main/pa_table.C, revision 1.53.2.10.2.2
1.14 paf 1: /** @file
1.15 paf 2: Parser: table class.
3:
1.53.2.8 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.44 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.48 paf 6: */
1.15 paf 7:
1.53.2.10.2.2! (paf 8:: static const char* IDENT_TABLE_C="$Date: 2003/03/18 15:14:19 $";
1.2 paf 9:
1.1 paf 10: #include "pa_table.h"
1.53.2.10.2.1 (paf 11::
1.25 paf 12: #include "pa_exception.h"
1.1 paf 13:
1.53.2.10.2.2! (paf 14:: Table::Table(columns_type acolumns, int initial_rows):
1.53.2.1 paf 15: Array<element_type>(initial_rows),
1.13 paf 16:
1.5 paf 17: fcurrent(0),
18: fcolumns(acolumns),
1.53.2.10.2.2! (paf 19:: name2number(new name2number_hash_class) {
1.1 paf 20:
1.53.2.10.2.2! (paf 21:: if(fcolumns)
1.53.2.1 paf 22: for(int i=0; i<fcolumns->count(); i++) {
1.53.2.10.2.2! (paf 23:: const String& name=*fcolumns->get(i);
1.53.2.1 paf 24: name2number->put(name, i+1);
1.1 paf 25: }
1.42 paf 26: }
27:
1.53.2.1 paf 28: Table::Table(const Table& src, int offset, int limit) :
29: Array<element_type>(limit/*may be more than needed, no harm done*/),
1.42 paf 30:
1.51 paf 31: fcurrent(0),
1.53.2.1 paf 32: fcolumns(src.fcolumns),
33: name2number(src.name2number) {
1.42 paf 34:
1.53.2.1 paf 35: append(src, offset, limit);
1.2 paf 36: }
37:
1.53.2.10.2.1 (paf 38:: int Table::column_name2index(const String& column_name, bool bark) const {
1.53.2.10.2.2! (paf 39:: if(fcolumns) {// named
! 40:: int result=name2number->get(column_name)-1; // -1 = column not found
1.29 paf 41: if(bark && result<0)
1.45 paf 42: throw Exception("parser.runtime",
1.53.2.10.2.2! (paf 43:: &column_name,
1.29 paf 44: "column not found");
45: return result;
1.53.2.2 paf 46: } else // nameless
1.53.2.10.2.2! (paf 47:: return column_name.as_int();
1.21 paf 48: }
49:
1.53.2.10.2.2! (paf 50:: const String* Table::item(int column) {
1.21 paf 51: if(valid(fcurrent)) {
1.53.2.6 paf 52: element_type row=get(fcurrent);
1.53.2.2 paf 53: if(column>=0 && column<row->count()) // proper index?
54: return row->get(column);
1.21 paf 55: }
1.53.2.10.2.1 (paf 56:: return 0; // it's OK we don't have row|column, just return nothing
1.21 paf 57: }
58:
1.53.2.10.2.1 (paf 59:: bool Table::locate(int column, const String& value) {
1.31 parser 60: int scurrent=fcurrent;
1.53.2.2 paf 61: for(fcurrent=0; fcurrent<count(); fcurrent++) {
1.53.2.10.2.2! (paf 62:: const String* item_value=item(column);
! 63:: if(*item_value == value)
1.21 paf 64: return true;
1.2 paf 65: }
66:
1.31 parser 67: fcurrent=scurrent;
1.21 paf 68: return false;
1.28 paf 69: }
70:
1.53.2.10.2.1 (paf 71:: bool Table::locate(const String& column, const String& value) {
1.29 paf 72: return locate(column_name2index(column, true), value);
1.22 paf 73: }
74:
1.41 paf 75: void Table::offset(bool absolute, int offset) {
1.53.2.2 paf 76: if(count())
77: fcurrent=((absolute?0:fcurrent)+offset+count())%count();
1.1 paf 78: }
E-mail: