Annotation of parser3/src/types/pa_vtable.C, revision 1.4
1.1 parser 1: /** @file
2: Parser: @b table class.
3:
4: Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com)
5:
6: Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf)
7: */
1.4 ! parser 8: static const char *RCSId="$Id: date.C,v 1.6 2001/09/04 10:50:19 parser Exp $";
1.1 parser 9:
10: #include "pa_vtable.h"
11: #include "pa_vstring.h"
12:
1.3 parser 13: #ifndef DOXYGEN
1.1 parser 14: struct Record_info {
15: Pool *pool;
16: Table *table;
17: Hash *hash;
18: };
1.3 parser 19: #endif
1.1 parser 20: static void store_column_item_to_hash(Array::Item *item, void *info) {
21: Record_info& ri=*static_cast<Record_info *>(info);
22: String& column_name=*static_cast<String *>(item);
23: Value *value;
24: if(const String *column_item=ri.table->item(column_name))
25: value=new(*ri.pool) VString(*column_item);
26: else
27: value=new(*ri.pool) VVoid(*ri.pool);
28: ri.hash->put(column_name, value);
29: }
30: Value *VTable::fields_element() {
31: if(const Array *columns=table().columns()) {
32: Value *result=NEW VHash(pool());
33: Record_info record_info={&pool(), &table(), result->get_hash()};
34: columns->for_each(store_column_item_to_hash, &record_info);
35: return result;
36: }
37: return 0;
38: }
39:
40:
41: Value *VTable::get_element(const String& name) {
42: // fields
43: if(name==TABLE_FIELDS_ELEMENT_NAME)
44: return fields_element();
45:
1.2 parser 46: // methods
47: if(Value *result=VStateless_object::get_element(name))
48: return result;
49:
1.1 parser 50: // columns
51: if(ftable) {
52: int index=ftable->column_name2index(name, false);
53: if(index>=0) // column name|number valid
54: if(const String *string=ftable->item(index)) // there is such column
55: return NEW VString(*string);
56: else
57: return NEW VVoid(pool());
58: }
59:
60: THROW(0, 0,
61: &name,
62: "column not found");
63: return 0; //unreached
64: }
E-mail: