Annotation of parser3/src/types/pa_vtable.C, revision 1.9
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
4: Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
1.9 ! paf 5: Author: Alexander Petrosyan <paf@design.ru>(http://paf.design.ru)
1.1 parser 6:
1.9 ! paf 7: $Id: pa_vtable.C,v 1.8 2001/10/23 14:43:44 parser Exp $
1.1 parser 8: */
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() {
32: if(const Array *columns=table().columns()) {
33: Value *result=NEW VHash(pool());
1.8 parser 34: Record_info record_info={&pool(), &table(), result->get_hash(0)};
1.1 parser 35: columns->for_each(store_column_item_to_hash, &record_info);
36: return result;
37: }
38: return 0;
39: }
40:
41:
42: Value *VTable::get_element(const String& name) {
43: // fields
44: if(name==TABLE_FIELDS_ELEMENT_NAME)
45: return fields_element();
46:
1.2 parser 47: // methods
48: if(Value *result=VStateless_object::get_element(name))
49: return result;
50:
1.1 parser 51: // columns
52: if(ftable) {
53: int index=ftable->column_name2index(name, false);
54: if(index>=0) // column name|number valid
55: if(const String *string=ftable->item(index)) // there is such column
56: return NEW VString(*string);
57: else
58: return NEW VVoid(pool());
59: }
60:
1.7 parser 61: throw Exception(0, 0,
1.1 parser 62: &name,
63: "column not found");
64: return 0; //unreached
65: }
E-mail: