Annotation of parser3/src/types/pa_vtable.h, revision 1.24

1.6       paf         1: /** @file
1.15      paf         2:        Parser: @b table parser class decl.
1.6       paf         3: 
1.1       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6       paf         5: 
1.1       paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: 
1.24    ! parser      8:        $Id: pa_vtable.h,v 1.23 2001/05/08 08:15:00 paf Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_VTABLE_H
                     12: #define PA_VTABLE_H
                     13: 
                     14: #include "pa_vstateless_object.h"
                     15: #include "pa_table.h"
1.24    ! parser     16: #include "pa_vnothing.h"
1.1       paf        17: 
1.16      paf        18: extern Methoded *table_class;
                     19: 
1.6       paf        20: /// value of type 'table'. implemented with Table
1.1       paf        21: class VTable : public VStateless_object {
                     22: public: // Value
                     23: 
                     24:        const char *type() const { return "table"; }
1.6       paf        25:        /// extract VTable
1.10      paf        26:        Table *get_table() { return ftable; }
1.18      paf        27:        /// VTable: columns,methods
1.1       paf        28:        Value *get_element(const String& name) {
1.17      paf        29:                // columns
1.18      paf        30:                if(ftable) {
1.23      paf        31:                        int index=ftable->column_name2index(name, false);
1.19      paf        32:                        if(index>=0) // column name|number valid
                     33:                                if(const String *string=ftable->item(index)) // there is such column
                     34:                                        return NEW VString(*string);
1.22      paf        35:                                else
                     36:                                        return NEW VUnknown(pool());
1.18      paf        37:                }
1.17      paf        38: 
1.3       paf        39:                // methods
1.2       paf        40:                if(Value *result=VStateless_object::get_element(name))
                     41:                        return result;
1.1       paf        42: 
1.18      paf        43:                THROW(0, 0,
                     44:                        &name, 
                     45:                        "column not found");
                     46:                return 0; //unreached
1.1       paf        47:        }
1.7       paf        48: 
                     49: protected: // VAliased
                     50: 
1.9       paf        51:        /// disable .CLASS element. @see VAliased::get_element
1.13      paf        52:        bool hide_class() { return true; }
1.1       paf        53: 
                     54: public: // usage
                     55: 
1.12      paf        56:        VTable(Pool& apool, Table* atable=0) : VStateless_object(apool, *table_class), 
1.21      paf        57:                ftable(atable), locked(false) {
1.1       paf        58:        }
1.16      paf        59:        void lock() { 
                     60:                check_lock();
                     61:                locked=true; 
                     62:        }
1.14      paf        63:        void unlock() { locked=false; }
                     64:        void set_table(Table& avalue) { 
1.16      paf        65:                check_lock();
1.14      paf        66:                ftable=&avalue; 
                     67:        }
1.1       paf        68:        Table& table() { 
1.4       paf        69:                if(!ftable)
1.1       paf        70:                        bark("getting unset vtable value");
                     71: 
1.4       paf        72:                return *ftable; 
1.1       paf        73:        }
                     74: 
                     75: private:
                     76: 
1.16      paf        77:        void check_lock() {
                     78:                if(locked)
                     79:                        bark("is locked");
                     80:        }
1.18      paf        81: 
                     82: private:
                     83: 
                     84:        Table *ftable;
                     85:        bool locked;
1.1       paf        86: 
                     87: };
                     88: 
                     89: #endif

E-mail: