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

1.14      paf         1: /** @file
1.15      paf         2:        Parser: table class decl.
                      3: 
1.48      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.41      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_TABLE_H
                      9: #define PA_TABLE_H
1.45      paf        10: 
1.49    ! paf        11: static const char* IDENT_TABLE_H="$Date: 2003/01/21 15:51:12 $";
1.1       paf        12: 
                     13: #include "pa_types.h"
                     14: #include "pa_array.h"
                     15: #include "pa_hash.h"
1.2       paf        16: #include "pa_string.h"
1.1       paf        17: 
1.16      paf        18: /** 
1.19      paf        19:        VTable backend.
1.16      paf        20: 
                     21:        holds:
1.14      paf        22:        - column names[if any]
                     23:        - data rows
                     24:        - current row pointer
                     25: 
                     26:        uses String for column names and data items
                     27: 
1.28      paf        28:        hence most of tables are "named", no need to uptimize nameless onces.
                     29:        rows and strings stored are read-only. once stored they can be removed,
                     30:        but not altered. that's handy for quick copying & co. see table:join
1.14      paf        31: */
1.1       paf        32: class Table : public Array {
                     33: public:
1.49    ! paf        34:        struct Action_options {
        !            35:             int offset;
        !            36:             int limit; //< negative limit means 'all'. zero limit means 'nothing'
        !            37:             bool reverse;
        !            38:             bool defined;
        !            39: 
        !            40:             Action_options(): offset(0), limit(-1), reverse(false), defined(false) {}
        !            41:        };
1.1       paf        42: 
1.11      paf        43:        Table(Pool& apool,
1.21      paf        44:                const String *aorigin,
1.34      parser     45:                const Array *acolumns,
1.2       paf        46:                int initial_rows=CR_INITIAL_ROWS_DEFAULT);
1.49    ! paf        47:        Table(Pool& apool, const Table& source, Action_options& options);
1.2       paf        48: 
1.21      paf        49:        /// where this table came from, may be NULL
                     50:        const String *origin_string() { return forigin_string; }
                     51: 
1.42      paf        52:        /// gets column names
1.5       paf        53:        const Array *columns() { return fcolumns; }
1.42      paf        54: 
                     55:        /// assignes column names
                     56:        void set_columns(const Array *acolumns) { fcolumns=acolumns; }
1.5       paf        57: 
1.18      paf        58:        /// moves @a current pointer
1.49    ! paf        59:        void set_current(int acurrent); /// @return current pointer
1.47      paf        60:        int current() const { return fcurrent; }
1.37      paf        61:        void offset(bool absolute, int offset);
1.5       paf        62: 
1.32      paf        63:        /** @return column index from @a column_name. '<0' if no such column
                     64:                if no such colum conditionally 'bark'
                     65:        */
                     66:        int column_name2index(const String& column, bool bark) const;
1.30      paf        67: 
1.26      paf        68:        /// @return item from @a column
                     69:        const String *item(int column) const;
1.30      paf        70: 
                     71:        /// @return item from @a column. '0' if no such column
                     72:        const String *item(const String& column) const {
1.32      paf        73:                int index=column_name2index(column, false);
1.30      paf        74:                return index>=0?item(index):0;
1.24      paf        75:        }
1.23      paf        76: 
                     77:        /// saves to text file
                     78:        void save(bool nameless_save, const String& file_spec);
1.2       paf        79: 
1.49    ! paf        80:        typedef bool (*locate_func)(Table& self, void* info);
        !            81:        bool locate(locate_func func, void* info, Action_options& options);
        !            82:        bool locate(int column, const String& value, Action_options& options);
        !            83:        bool locate(const String& column, const String& value, Action_options& options);
1.24      paf        84: 
1.27      paf        85:        const Array& at(int index) const {
                     86:                // force @c const result
                     87:                return *const_cast<const Array *>(static_cast<Array *>(get(index)));
                     88:        }
                     89: 
1.12      paf        90: private:
1.21      paf        91:        
                     92:        // where this table came from, may be NULL
                     93:        const String *forigin_string;
1.5       paf        94: 
1.1       paf        95:        // column name->number lookup table
1.44      paf        96:        Hash& name2number;
1.1       paf        97: 
1.5       paf        98:        // current row
                     99:        int fcurrent;
                    100: 
                    101:        // columns
1.34      parser    102:        const Array *fcolumns;
1.5       paf       103: 
1.24      paf       104:        bool valid(int index) const { return index>=0 && index<size(); }
1.2       paf       105: 
1.1       paf       106: };
                    107: 
                    108: #endif

E-mail: