Annotation of parser3/src/main/pa_table.C, revision 1.53.2.2

1.14      paf         1: /** @file
1.15      paf         2:        Parser: table class.
                      3: 
1.53      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.2! paf         8: static const char* IDENT_TABLE_C="$Date: 2003/01/23 15:38:06 $";
1.1       paf         9: 
1.48      paf        10: //#include <stdlib.h>
1.2       paf        11: 
1.1       paf        12: #include "pa_table.h"
                     13: #include "pa_pool.h"
1.25      paf        14: #include "pa_exception.h"
1.1       paf        15: 
1.53.2.1  paf        16: Table::Table(
                     17:                         object_ptr<const String> aorigin_string,
1.53.2.2! paf        18:                         object_ptr<const Array<column_type> > acolumns,
1.53.2.1  paf        19:                         int initial_rows):
                     20:        Array<element_type>(initial_rows),
1.13      paf        21: 
1.18      paf        22:        forigin_string(aorigin_string),
1.5       paf        23:        fcurrent(0),
                     24:        fcolumns(acolumns), 
1.53.2.1  paf        25:        name2number(object_ptr<name2number_hash_class>(new name2number_hash_class)) {
1.1       paf        26: 
1.53.2.1  paf        27:        if(fcolumns.get())
                     28:                for(int i=0; i<fcolumns->count(); i++) {
1.53.2.2! paf        29:                        const String& name=*fcolumns->get(i).get();
1.53.2.1  paf        30:                        name2number->put(name, i+1);
1.1       paf        31:                }
1.42      paf        32: }
                     33: 
1.53.2.1  paf        34: Table::Table(const Table& src, int offset, int limit) :
                     35:        Array<element_type>(limit/*may be more than needed, no harm done*/),
1.42      paf        36: 
1.53.2.1  paf        37:        forigin_string(src.forigin_string),
1.51      paf        38:        fcurrent(0),
1.53.2.1  paf        39:        fcolumns(src.fcolumns),
                     40:        name2number(src.name2number) {
1.42      paf        41: 
1.53.2.1  paf        42:        append(src, offset, limit);
1.2       paf        43: }
                     44: 
1.53.2.1  paf        45: int Table::column_name2index(object_ptr<const String> column_name, bool bark) const {
                     46:        if(fcolumns.get()) {// named
                     47:                int result=name2number->get(*column_name.get())-1; // -1 = column not found
1.29      paf        48:                if(bark && result<0)
1.45      paf        49:                        throw Exception("parser.runtime",
1.53.2.1  paf        50:                                column_name,
1.29      paf        51:                                "column not found");
                     52:                return result;
1.53.2.2! paf        53:        } else // nameless
        !            54:                return column_name->as_int();
1.21      paf        55: }
                     56: 
1.53.2.2! paf        57: Table::value_type Table::item(int column) const {
1.21      paf        58:        if(valid(fcurrent)) {
1.53.2.2! paf        59:                element_type row=at(fcurrent);
        !            60:                if(column>=0 && column<row->count()) // proper index?
        !            61:                        return row->get(column);
1.21      paf        62:        }
                     63:        return 0; // it's OK we don't have row|column, just return nothing
                     64: }
                     65: 
1.53.2.2! paf        66: bool Table::locate(int column, value_type value) {
1.31      parser     67:        int scurrent=fcurrent;
1.53.2.2! paf        68:        for(fcurrent=0; fcurrent<count(); fcurrent++) {
        !            69:                value_type item_value=item(column);
        !            70:                if(item_value.get() == value.get())
1.21      paf        71:                        return true;
1.2       paf        72:        }
                     73: 
1.31      parser     74:        fcurrent=scurrent;
1.21      paf        75:        return false;
1.28      paf        76: }
                     77: 
1.53.2.2! paf        78: bool Table::locate(column_type column, value_type value) {
1.29      paf        79:        return locate(column_name2index(column, true), value);
1.22      paf        80: }
                     81: 
1.41      paf        82: void Table::offset(bool absolute, int offset) {
1.53.2.2! paf        83:        if(count())
        !            84:                fcurrent=((absolute?0:fcurrent)+offset+count())%count();
1.1       paf        85: }

E-mail: