Annotation of parser3/src/main/pa_table.C, revision 1.17
1.14 paf 1: /** @file
1.15 paf 2: Parser: table class.
3:
1.10 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.15 paf 5:
1.11 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.10 paf 7:
1.17 ! paf 8: $Id: pa_table.C,v 1.16 2001/03/21 14:06:46 paf Exp $
1.1 paf 9: */
10:
1.2 paf 11: #include <stdlib.h>
12:
1.1 paf 13: #include "pa_table.h"
14: #include "pa_pool.h"
15:
1.12 paf 16: Table::Table(Pool& apool,
1.1 paf 17: Array *acolumns,
18: int initial_rows) :
1.12 paf 19: Array(apool, initial_rows),
1.13 paf 20:
1.5 paf 21: fcurrent(0),
22: fcolumns(acolumns),
1.12 paf 23: name2number(pool(), false) {
1.1 paf 24:
1.5 paf 25: if(fcolumns)
26: for(int i=0; i<fcolumns->size(); i++) {
1.12 paf 27: const String& name=*fcolumns->get_string(i);
1.2 paf 28: name2number.put(name, i+1);
1.1 paf 29: }
1.2 paf 30: }
31:
1.7 paf 32: const Array &Table::at(int index) {
1.16 paf 33: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
1.2 paf 34: }
35:
1.12 paf 36: const String *Table::item(const String& column_name) {
1.2 paf 37: int column_index;
1.12 paf 38: if(fcolumns) { // named
1.2 paf 39: int found_index=name2number.get_int(column_name);
40: if(found_index)
41: column_index=found_index-1;
42: else
1.9 paf 43: THROW(0, 0,
1.6 paf 44: &column_name,
45: "column not found");
1.12 paf 46: } else { // nameless
1.2 paf 47: column_index=atoi(column_name.cstr());
1.13 paf 48: if(!valid(fcurrent))
49: return 0; // it's OK we don't have row, just return nothing
1.7 paf 50: const Array& row=at(fcurrent);
1.12 paf 51: if(column_index<0 || column_index>=row.size()) // read past proper index?
1.13 paf 52: return 0; // it's OK we don't have column, just return nothing
1.2 paf 53: }
54:
55: return item(column_index);
1.1 paf 56: }
E-mail: