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

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.26    ! paf         8:        $Id: pa_table.h,v 1.25 2001/03/28 09:01:21 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: /** 
1.19      paf        21:        VTable backend.
1.16      paf        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.21      paf        36:                const String *aorigin,
1.2       paf        37:                Array *acolumns,
                     38:                int initial_rows=CR_INITIAL_ROWS_DEFAULT);
                     39: 
1.21      paf        40:        /// where this table came from, may be NULL
                     41:        const String *origin_string() { return forigin_string; }
                     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.25      paf        49:        int current() { return fcurrent; }
                     50:        void shift(int offset);
1.5       paf        51: 
1.26    ! paf        52:        /// @return item from @a column
        !            53:        const String *item(int column) const;
        !            54:        /// @return item from @a column
1.24      paf        55:        const String *item(const String& column) const { 
                     56:                return item(column_name2index(column)); 
                     57:        }
1.23      paf        58: 
                     59:        /// saves to text file
                     60:        void save(bool nameless_save, const String& file_spec);
1.2       paf        61: 
1.26    ! paf        62:        bool locate(int column, const String& value);
        !            63:        bool locate(const String& column, const String& value) {
        !            64:                return locate(column_name2index(column), value);
        !            65:        }
1.24      paf        66: 
1.12      paf        67: private:
1.21      paf        68:        
                     69:        // where this table came from, may be NULL
                     70:        const String *forigin_string;
1.5       paf        71: 
1.1       paf        72:        // column name->number lookup table
                     73:        Hash name2number;
                     74: 
1.5       paf        75:        // current row
                     76:        int fcurrent;
                     77: 
                     78:        // columns
                     79:        Array *fcolumns;
                     80: 
1.24      paf        81:        bool valid(int index) const { return index>=0 && index<size(); }
                     82: 
                     83:        const Array& at(int index) const {
                     84:                // force @c const result
                     85:                return *const_cast<const Array *>(static_cast<Array *>(get(index)));
                     86:        }
                     87: 
                     88:        /// @return column index from @a column_name
1.25      paf        89:        int column_name2index(const String& column) const;
1.12      paf        90: 
1.2       paf        91: 
1.1       paf        92: };
                     93: 
                     94: #endif

E-mail: