Annotation of parser3/src/types/pa_vtable.C, revision 1.21.2.2
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
1.21.2.1 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.2.2! paf 8: static const char* IDENT_VTABLE_C="$Date: 2003/01/31 12:34:46 $";
1.1 parser 9:
1.21.2.2! paf 10: #include "pa_value_includes.h"
1.1 parser 11: #include "pa_vtable.h"
12: #include "pa_vstring.h"
1.5 parser 13: #include "pa_vhash.h"
1.21.2.2! paf 14: #include "pa_vvoid.h"
1.1 parser 15:
1.3 parser 16: #ifndef DOXYGEN
1.1 parser 17: struct Record_info {
1.21.2.2! paf 18: Table* table;
! 19: HashStringValue* hash;
1.1 parser 20: };
1.3 parser 21: #endif
1.21.2.2! paf 22: static void store_column_item_to_hash(StringPtr column_name,
! 23: Record_info *info) {
! 24: ValuePtr value;
! 25: if(StringPtr column_item=info->table->item(column_name))
! 26: value=ValuePtr(new VString(column_item));
1.1 parser 27: else
1.21.2.2! paf 28: value=ValuePtr(new VVoid);
! 29: info->hash->put(column_name, value);
1.1 parser 30: }
1.21.2.2! paf 31: ValuePtr VTable::fields_element() {
! 32: Table& ltable=*table(Exception::undefined_source);
! 33: if(Table::columns_type columns=ltable.columns()) {
! 34: ValuePtr result(new VHash);
! 35: Record_info record_info={<able, result->get_hash(Exception::undefined_source)};
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.21.2.2! paf 43: ValuePtr VTable::get_element(StringPtr aname, Value& aself, bool looking_up) {
1.1 parser 44: // fields
1.21.2.2! paf 45: if(*aname==TABLE_FIELDS_ELEMENT_NAME)
1.1 parser 46: return fields_element();
47:
1.2 parser 48: // methods
1.21.2.2! paf 49: if(ValuePtr 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.21.2.2! paf 56: if(StringPtr string=ftable->item(index)) // there is such column
! 57: return ValuePtr(new VString(string));
1.1 parser 58: else
1.21.2.2! paf 59: return ValuePtr(new VVoid);
1.1 parser 60: }
61:
1.13 paf 62: throw Exception("parser.runtime",
1.21.2.2! paf 63: aname,
1.1 parser 64: "column not found");
65: return 0; //unreached
66: }
E-mail: