Annotation of parser3/src/types/pa_vtable.C, revision 1.1

1.1     ! parser      1: /** @file
        !             2:        Parser: @b table class.
        !             3: 
        !             4:        Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
        !             5: 
        !             6:        Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
        !             7: 
        !             8:        $Id: pa_vtable.C,v 1.9 2001/07/18 10:06:04 parser Exp $
        !             9: */
        !            10: 
        !            11: #include "pa_vtable.h"
        !            12: #include "pa_vstring.h"
        !            13: 
        !            14: /// used by table: _record / store_column_item_to_hash
        !            15: struct Record_info {
        !            16:        Pool *pool;
        !            17:        Table *table;
        !            18:        Hash *hash;
        !            19: };
        !            20: static void store_column_item_to_hash(Array::Item *item, void *info) {
        !            21:        Record_info& ri=*static_cast<Record_info *>(info);
        !            22:        String& column_name=*static_cast<String *>(item);
        !            23:        Value *value;
        !            24:        if(const String *column_item=ri.table->item(column_name))
        !            25:                value=new(*ri.pool) VString(*column_item);
        !            26:        else
        !            27:                value=new(*ri.pool) VVoid(*ri.pool);
        !            28:        ri.hash->put(column_name, value);
        !            29: }
        !            30: Value *VTable::fields_element() {
        !            31:        if(const Array *columns=table().columns()) {
        !            32:                Value *result=NEW VHash(pool());
        !            33:                Record_info record_info={&pool(), &table(), result->get_hash()};
        !            34:                columns->for_each(store_column_item_to_hash, &record_info);
        !            35:                return result;
        !            36:        }
        !            37:        return 0;
        !            38: }
        !            39: 
        !            40: 
        !            41: Value *VTable::get_element(const String& name) {
        !            42:        // fields
        !            43:        if(name==TABLE_FIELDS_ELEMENT_NAME)
        !            44:                return fields_element();
        !            45: 
        !            46:        // columns
        !            47:        if(ftable) {
        !            48:                int index=ftable->column_name2index(name, false);
        !            49:                if(index>=0) // column name|number valid
        !            50:                        if(const String *string=ftable->item(index)) // there is such column
        !            51:                                return NEW VString(*string);
        !            52:                        else
        !            53:                                return NEW VVoid(pool());
        !            54:        }
        !            55: 
        !            56:        // methods
        !            57:        if(Value *result=VStateless_object::get_element(name))
        !            58:                return result;
        !            59: 
        !            60:        THROW(0, 0,
        !            61:                &name, 
        !            62:                "column not found");
        !            63:        return 0; //unreached
        !            64: }

E-mail: