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

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.10      paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.9       paf         6: 
1.35    ! parser      7:        $Id: pa_table.h,v 1.34 2001/08/10 07:02:43 parser Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_TABLE_H
                     11: #define PA_TABLE_H
                     12: 
1.33      parser     13: #include "pa_config_includes.h"
1.1       paf        14: #include "pa_types.h"
                     15: #include "pa_array.h"
                     16: #include "pa_hash.h"
1.2       paf        17: #include "pa_string.h"
1.1       paf        18: 
1.16      paf        19: /** 
1.19      paf        20:        VTable backend.
1.16      paf        21: 
                     22:        holds:
1.14      paf        23:        - column names[if any]
                     24:        - data rows
                     25:        - current row pointer
                     26: 
                     27:        uses String for column names and data items
                     28: 
1.28      paf        29:        hence most of tables are "named", no need to uptimize nameless onces.
                     30:        rows and strings stored are read-only. once stored they can be removed,
                     31:        but not altered. that's handy for quick copying & co. see table:join
1.14      paf        32: */
1.1       paf        33: class Table : public Array {
                     34: public:
                     35: 
1.11      paf        36:        Table(Pool& apool,
1.21      paf        37:                const String *aorigin,
1.34      parser     38:                const Array *acolumns,
1.2       paf        39:                int initial_rows=CR_INITIAL_ROWS_DEFAULT);
                     40: 
1.21      paf        41:        /// where this table came from, may be NULL
                     42:        const String *origin_string() { return forigin_string; }
                     43: 
1.14      paf        44:        /// column names
1.5       paf        45:        const Array *columns() { return fcolumns; }
                     46: 
1.18      paf        47:        /// moves @a current pointer
1.5       paf        48:        void set_current(int acurrent) { fcurrent=acurrent; }
1.17      paf        49:        /// @return current pointer
1.25      paf        50:        int current() { return fcurrent; }
                     51:        void shift(int offset);
1.5       paf        52: 
1.32      paf        53:        /** @return column index from @a column_name. '<0' if no such column
                     54:                if no such colum conditionally 'bark'
                     55:        */
                     56:        int column_name2index(const String& column, bool bark) const;
1.30      paf        57: 
1.26      paf        58:        /// @return item from @a column
                     59:        const String *item(int column) const;
1.30      paf        60: 
                     61:        /// @return item from @a column. '0' if no such column
                     62:        const String *item(const String& column) const {
1.32      paf        63:                int index=column_name2index(column, false);
1.30      paf        64:                return index>=0?item(index):0;
1.24      paf        65:        }
1.23      paf        66: 
                     67:        /// saves to text file
                     68:        void save(bool nameless_save, const String& file_spec);
1.2       paf        69: 
1.26      paf        70:        bool locate(int column, const String& value);
1.31      paf        71:        bool locate(const String& column, const String& value);
1.24      paf        72: 
1.27      paf        73:        const Array& at(int index) const {
                     74:                // force @c const result
                     75:                return *const_cast<const Array *>(static_cast<Array *>(get(index)));
                     76:        }
                     77: 
1.12      paf        78: private:
1.21      paf        79:        
                     80:        // where this table came from, may be NULL
                     81:        const String *forigin_string;
1.5       paf        82: 
1.1       paf        83:        // column name->number lookup table
                     84:        Hash name2number;
                     85: 
1.5       paf        86:        // current row
                     87:        int fcurrent;
                     88: 
                     89:        // columns
1.34      parser     90:        const Array *fcolumns;
1.5       paf        91: 
1.24      paf        92:        bool valid(int index) const { return index>=0 && index<size(); }
1.2       paf        93: 
1.1       paf        94: };
                     95: 
                     96: #endif

E-mail: