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

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.6! (paf        8:: static const char* IDENT_TABLE_C="$Date: 2003/04/11 15:00:05 $";
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.6! (paf       14:: Table::Table(columns_type acolumns, size_t 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.3  (paf       21::       if(fcolumns) {
                     22::               size_t fcolumns_count=fcolumns->count();
1.53.2.10.2.5  (paf       23::               size_t number=1;
                     24::               for(Array_iterator<const String*> i(*fcolumns); i.has_next(); ) {
                     25::                       const String& name=*i.next();
                     26::                       name2number->put(name, number++);
1.1       paf        27:                }
1.53.2.10.2.3  (paf       28::       }
1.42      paf        29: }
                     30: 
1.53.2.10.2.6! (paf       31:: Table::Table(const Table& src, Action_options& options) :
        !            32::       Array<element_type>(options.limit==ARRAY_OPTION_LIMIT_ALL?0:options.limit/*may be more than needed, no harm done*/),
1.42      paf        33: 
1.51      paf        34:        fcurrent(0),
1.53.2.1  paf        35:        fcolumns(src.fcolumns),
                     36:        name2number(src.name2number) {
1.42      paf        37: 
1.53.2.10.2.6! (paf       38::       append(src, options.offset, options.limit, options.reverse);
1.2       paf        39: }
                     40: 
1.53.2.10.2.1  (paf       41:: int Table::column_name2index(const String& column_name, bool bark) const {
1.53.2.10.2.2  (paf       42::       if(fcolumns) {// named
                     43::               int result=name2number->get(column_name)-1; // -1 = column not found
1.29      paf        44:                if(bark && result<0)
1.45      paf        45:                        throw Exception("parser.runtime",
1.53.2.10.2.2  (paf       46::                               &column_name,
1.29      paf        47:                                "column not found");
                     48:                return result;
1.53.2.2  paf        49:        } else // nameless
1.53.2.10.2.2  (paf       50::               return column_name.as_int();
1.21      paf        51: }
                     52: 
1.53.2.10.2.3  (paf       53:: const String* Table::item(size_t column) {
1.21      paf        54:        if(valid(fcurrent)) {
1.53.2.6  paf        55:                element_type row=get(fcurrent);
1.53.2.2  paf        56:                if(column>=0 && column<row->count()) // proper index?
1.53.2.10.2.4  (paf       57::                       return row->get(column);
1.21      paf        58:        }
1.53.2.10.2.1  (paf       59::       return 0; // it's OK we don't have row|column, just return nothing
1.21      paf        60: }
                     61: 
1.53.2.10.2.6! (paf       62:: void Table::set_current(size_t acurrent) { 
        !            63::       if(acurrent>count())
        !            64::               throw Exception(0,
        !            65::                       0,
        !            66::                       "table row (%d) > table size (%d)", acurrent, count());
        !            67::       fcurrent=acurrent; 
        !            68:: }
        !            69:: 
        !            70:: #ifndef DOXYGEN
        !            71:: struct Locate_int_string_info {
        !            72::       int column;
        !            73::       const String* value;
        !            74:: };
        !            75:: #endif
        !            76:: bool locate_int_string(Table& self, void* ainfo) {
        !            77::       Locate_int_string_info& info=*static_cast<Locate_int_string_info*>(ainfo);
        !            78:: 
        !            79::       const String *item_value=self.item(info.column);
        !            80::       return item_value && *item_value==*info.value;
        !            81:: }
1.2       paf        82: 
1.53.2.10.2.6! (paf       83:: bool Table::locate(int column, const String& value,
        !            84::                  Table::Action_options& options) {
        !            85::       Locate_int_string_info info={column, &value};
        !            86::       return locate(locate_int_string, &info, options);
1.28      paf        87: }
                     88: 
1.53.2.10.2.6! (paf       89:: bool Table::locate(const String& column, const String& value, 
        !            90::                  Table::Action_options& options) {
        !            91::       return locate(column_name2index(column, true), value, options);
1.22      paf        92: }
                     93: 
1.41      paf        94: void Table::offset(bool absolute, int offset) {
1.53.2.10.2.3  (paf       95::       if(size_t lcount=count())
                     96::               fcurrent=((absolute?0:fcurrent)+offset+lcount)%lcount;
1.1       paf        97: }

E-mail: