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

1.1       parser      1: /** @file
                      2:        Parser: @b table class.
                      3: 
1.22    ! 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.22    ! paf         8: static const char* IDENT_VTABLE_C="$Date: 2003/03/24 12:53:04 $";
1.1       parser      9: 
                     10: #include "pa_vtable.h"
                     11: #include "pa_vstring.h"
1.5       parser     12: #include "pa_vhash.h"
1.22    ! paf        13: #include "pa_vvoid.h"
1.1       parser     14: 
1.3       parser     15: #ifndef DOXYGEN
1.1       parser     16: struct Record_info {
1.22    ! paf        17:        Table* table;
        !            18:        HashStringValue* hash;
1.1       parser     19: };
1.3       parser     20: #endif
1.22    ! paf        21: static void store_column_item_to_hash(const String* column_name, 
        !            22:                                      Record_info *info) {
        !            23:        Value* value;
        !            24:        if(const String* column_item=info->table->item(*column_name))
        !            25:                value=new VString(*column_item);
1.1       parser     26:        else
1.22    ! paf        27:                value=new VVoid;
        !            28:        info->hash->put(*column_name, value);
1.1       parser     29: }
1.22    ! paf        30: Value* VTable::fields_element() {
        !            31:        Table& ltable=table();
        !            32:        if(Table::columns_type columns=ltable.columns()) {
        !            33:                Value& result=*new VHash;
        !            34:                Record_info record_info={&ltable, result.get_hash()};
1.1       parser     35:                columns->for_each(store_column_item_to_hash, &record_info);
1.22    ! paf        36:                return &result;
1.1       parser     37:        }
                     38:        return 0;
                     39: }
                     40: 
                     41: 
1.22    ! paf        42: Value* VTable::get_element(const String& aname, Value& aself, bool looking_up) {
1.1       parser     43:        // fields
1.16      paf        44:        if(aname==TABLE_FIELDS_ELEMENT_NAME)
1.1       parser     45:                return fields_element();
                     46: 
1.2       parser     47:        // methods
1.22    ! paf        48:        if(Value* result=VStateless_object::get_element(aname, aself, looking_up))
1.2       parser     49:                return result;
                     50: 
1.1       parser     51:        // columns
                     52:        if(ftable) {
1.16      paf        53:                int index=ftable->column_name2index(aname, false);
                     54:                if(index>=0) // column aname|number valid
1.22    ! paf        55:                        if(const String* string=ftable->item(index)) // there is such column
        !            56:                                return new VString(*string);
1.1       parser     57:                        else
1.22    ! paf        58:                                return new VVoid;
1.1       parser     59:        }
                     60: 
1.13      paf        61:        throw Exception("parser.runtime",
1.16      paf        62:                &aname, 
1.1       parser     63:                "column not found");
                     64:        return 0; //unreached
                     65: }

E-mail: