Annotation of parser3/src/main/pa_table.C, revision 1.5
1.1 paf 1: /*
1.5 ! paf 2: $Id: pa_table.C,v 1.4 2001/01/29 21:51:52 paf Exp $
1.1 paf 3: */
4:
1.2 paf 5: #include <stdlib.h>
6:
1.1 paf 7: #include "pa_table.h"
8: #include "pa_pool.h"
9:
1.2 paf 10: Table::Table(Request& arequest,
1.1 paf 11: char *afile, uint aline,
12: Array *acolumns,
13: int initial_rows) :
1.2 paf 14: Array(arequest.pool, initial_rows),
15: request(arequest),
1.5 ! paf 16: fcurrent(0),
! 17: fcolumns(acolumns),
1.2 paf 18: name2number(arequest.pool, false) {
1.1 paf 19: #ifndef NO_STRING_ORIGIN
1.5 ! paf 20: forigin.file=afile;
! 21: forigin.line=aline;
1.1 paf 22: #endif
23:
1.5 ! paf 24: if(fcolumns)
! 25: for(int i=0; i<fcolumns->size(); i++) {
1.1 paf 26: String name(pool);
1.5 ! paf 27: name.APPEND(fcolumns->get_cstr(i), 0, 0);
1.2 paf 28: name2number.put(name, i+1);
1.1 paf 29: }
1.2 paf 30: }
31:
1.3 paf 32: const Array *Table::at(int index) {
1.2 paf 33: if(index<0 || index>=size())
1.4 paf 34: request.operator_error.raise(0,
1.2 paf 35: "table column index %d is out of range [0..%d]",
36: index, size()-1);
37:
1.3 paf 38: return static_cast<const Array *>(get(index));
1.2 paf 39: }
40:
1.3 paf 41: const char *Table::item(int index) {
1.5 ! paf 42: const Array *row=at(fcurrent);
1.2 paf 43: return row->get_cstr(index);
44: }
45:
1.5 ! paf 46: const char *Table::item(const String& column_name) {
1.2 paf 47: int column_index;
1.5 ! paf 48: if(fcolumns) {
1.2 paf 49: int found_index=name2number.get_int(column_name);
50: if(found_index)
51: column_index=found_index-1;
52: else
1.4 paf 53: request.operator_error.raise(&column_name, "column not found");
1.2 paf 54: } else {
55: column_index=atoi(column_name.cstr());
1.5 ! paf 56: const Array *row=at(fcurrent);
1.2 paf 57: if(column_index<0 || column_index>=row->size())
1.4 paf 58: request.operator_error.raise(&column_name,
1.2 paf 59: "table column index %d is out of range [0..%d]",
60: column_index, row->size()-1);
61: }
62:
63: return item(column_index);
1.1 paf 64: }
1.5 ! paf 65:
E-mail: