Annotation of parser3/src/include/pa_table.h, revision 1.18

1.14      paf         1: /** @file
1.15      paf         2:        Parser: table class decl.
                      3: 
1.9       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.15      paf         5: 
1.10      paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.9       paf         7: 
1.18    ! paf         8:        $Id: pa_table.h,v 1.17 2001/03/19 20:07:37 paf Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_TABLE_H
                     12: #define PA_TABLE_H
                     13: 
                     14: #include "pa_types.h"
                     15: #include "pa_array.h"
                     16: #include "pa_hash.h"
1.2       paf        17: #include "pa_string.h"
                     18: #include "pa_request.h"
1.1       paf        19: 
1.16      paf        20: /** 
                     21:        parser \b table class backend.
                     22: 
                     23:        holds:
1.14      paf        24:        - column names[if any]
                     25:        - data rows
                     26:        - current row pointer
                     27: 
                     28:        uses String for column names and data items
                     29: 
                     30:        hence most of tables are "named", no need to uptimize nameless onces
                     31: */
1.1       paf        32: class Table : public Array {
                     33: public:
                     34: 
1.11      paf        35:        Table(Pool& apool,
1.12      paf        36:                const String& asource,
1.2       paf        37:                Array *acolumns,
                     38:                int initial_rows=CR_INITIAL_ROWS_DEFAULT);
                     39: 
1.14      paf        40:        /// the string source of table's data
                     41:        //const String& source() { return fsource; }
1.5       paf        42: 
1.14      paf        43:        /// column names
1.5       paf        44:        const Array *columns() { return fcolumns; }
                     45: 
1.18    ! paf        46:        /// moves @a current pointer
1.5       paf        47:        void set_current(int acurrent) { fcurrent=acurrent; }
1.17      paf        48:        /// @return current pointer
1.5       paf        49:        int get_current() { return fcurrent; }
                     50: 
1.18    ! paf        51:        /// @return item from @a column_name
1.11      paf        52:        const String *item(const String& column_name);
1.2       paf        53: 
1.12      paf        54: private:
1.1       paf        55: 
1.5       paf        56:        // the base origin of table's data
1.12      paf        57:        const String& fsource;
1.5       paf        58: 
1.1       paf        59:        // column name->number lookup table
                     60:        Hash name2number;
                     61: 
1.5       paf        62:        // current row
                     63:        int fcurrent;
                     64: 
                     65:        // columns
                     66:        Array *fcolumns;
                     67: 
1.12      paf        68:        bool valid(int index) { return index>=0 && index<size();        }
                     69: 
1.7       paf        70:        const Array& at(int index);
1.2       paf        71: 
1.11      paf        72:        const String *item(int column_index) {
1.12      paf        73:                return valid(fcurrent)?at(fcurrent).get_string(column_index):0;
1.11      paf        74:        }
1.1       paf        75: };
                     76: 
                     77: #endif

E-mail: