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

1.1       parser      1: /** @file
                      2:        Parser: @b table class.
                      3: 
1.21    ! paf         4:        Copyright(c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.11      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.14      paf         6: */
1.1       parser      7: 
1.21    ! paf         8: static const char* IDENT_VTABLE_C="$Date: 2002/10/31 15:01:57 $";
1.1       parser      9: 
                     10: #include "pa_vtable.h"
                     11: #include "pa_vstring.h"
1.5       parser     12: #include "pa_vhash.h"
1.1       parser     13: 
1.3       parser     14: #ifndef DOXYGEN
1.1       parser     15: struct Record_info {
                     16:        Pool *pool;
                     17:        Table *table;
                     18:        Hash *hash;
                     19: };
1.3       parser     20: #endif
1.1       parser     21: static void store_column_item_to_hash(Array::Item *item, void *info) {
                     22:        Record_info& ri=*static_cast<Record_info *>(info);
                     23:        String& column_name=*static_cast<String *>(item);
                     24:        Value *value;
                     25:        if(const String *column_item=ri.table->item(column_name))
                     26:                value=new(*ri.pool) VString(*column_item);
                     27:        else
                     28:                value=new(*ri.pool) VVoid(*ri.pool);
                     29:        ri.hash->put(column_name, value);
                     30: }
                     31: Value *VTable::fields_element() {
1.17      paf        32:        Table& ltable=table(0);
                     33:        if(const Array *columns=ltable.columns()) {
1.1       parser     34:                Value *result=NEW VHash(pool());
1.17      paf        35:                Record_info record_info={&pool(), &ltable, result->get_hash(0)};
1.1       parser     36:                columns->for_each(store_column_item_to_hash, &record_info);
                     37:                return result;
                     38:        }
                     39:        return 0;
                     40: }
                     41: 
                     42: 
1.20      paf        43: Value *VTable::get_element(const String& aname, Value& aself, bool looking_up) {
1.1       parser     44:        // fields
1.16      paf        45:        if(aname==TABLE_FIELDS_ELEMENT_NAME)
1.1       parser     46:                return fields_element();
                     47: 
1.2       parser     48:        // methods
1.19      paf        49:        if(Value *result=VStateless_object::get_element(aname, aself, looking_up))
1.2       parser     50:                return result;
                     51: 
1.1       parser     52:        // columns
                     53:        if(ftable) {
1.16      paf        54:                int index=ftable->column_name2index(aname, false);
                     55:                if(index>=0) // column aname|number valid
1.1       parser     56:                        if(const String *string=ftable->item(index)) // there is such column
                     57:                                return NEW VString(*string);
                     58:                        else
                     59:                                return NEW VVoid(pool());
                     60:        }
                     61: 
1.13      paf        62:        throw Exception("parser.runtime",
1.16      paf        63:                &aname, 
1.1       parser     64:                "column not found");
                     65:        return 0; //unreached
                     66: }

E-mail: