Annotation of parser3/src/types/pa_vtable.C, revision 1.32
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
1.28 misha 4: Copyright(c) 2001-2009 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.32 ! pretende 8: static const char * const IDENT_VTABLE_C="$Date: 2009-08-08 13:30:22 $";
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.29 misha 21:
22: static void store_column_item_to_hash(const String* column_name, Record_info *info) {
23: const String* column_item=info->table->item(*column_name);
24: info->hash->put(*column_name,
25: (column_item && !column_item->is_empty())
26: ?new VString(*column_item)
27: :new VString()
28: );
1.1 parser 29: }
1.29 misha 30:
1.22 paf 31: Value* VTable::fields_element() {
1.29 misha 32: Value& result=*new VHash;
1.22 paf 33: Table& ltable=table();
1.29 misha 34: if(!ltable.count())
35: return &result;
36:
37: HashStringValue* hash=result.get_hash();
38:
39: if(Table::columns_type columns=ltable.columns()) { // named
40: Record_info record_info={<able, hash};
1.1 parser 41: columns->for_each(store_column_item_to_hash, &record_info);
1.29 misha 42: } else { // nameless
43: size_t row_size=ltable[ltable.current()]->count(); // number of columns in current row
44: for(size_t index=0; index<row_size; index++){
45: const String* column_item=ltable.item(index);
46: hash->put(String::Body::Format(index),
47: (column_item && !column_item->is_empty())
48: ?new VString(*column_item)
49: :new VString()
50: );
51: }
1.1 parser 52: }
1.29 misha 53:
54: return &result;
1.1 parser 55: }
56:
1.31 misha 57: Value* VTable::get_element(const String& aname) {
1.1 parser 58: // fields
1.16 paf 59: if(aname==TABLE_FIELDS_ELEMENT_NAME)
1.1 parser 60: return fields_element();
61:
1.2 parser 62: // methods
1.31 misha 63: if(Value* result=VStateless_object::get_element(aname))
1.2 parser 64: return result;
65:
1.1 parser 66: // columns
67: if(ftable) {
1.16 paf 68: int index=ftable->column_name2index(aname, false);
69: if(index>=0) // column aname|number valid
1.32 ! pretende 70: {
! 71: const String* string=ftable->item(index); // there is such column
! 72: return new VString(string ? *string : String::Empty);
! 73: }
1.1 parser 74: }
75:
1.27 misha 76: throw Exception(PARSER_RUNTIME,
1.16 paf 77: &aname,
1.1 parser 78: "column not found");
79: }
E-mail: