|
|
| version 1.9, 2001/03/10 16:34:35 | version 1.17, 2001/03/19 20:07:37 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| Parser | Parser: table class decl. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> | |
| $Id$ | Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) |
| */ | |
| /* | $Id$ |
| hence most of tables are "named", no need to uptimize unnamed onces | |
| */ | */ |
| #ifndef PA_TABLE_H | #ifndef PA_TABLE_H |
| #define PA_TABLE_H | #define PA_TABLE_H |
| Line 20 | Line 17 |
| #include "pa_string.h" | #include "pa_string.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| /** | |
| parser \b table class backend. | |
| holds: | |
| - column names[if any] | |
| - data rows | |
| - current row pointer | |
| uses String for column names and data items | |
| hence most of tables are "named", no need to uptimize nameless onces | |
| */ | |
| class Table : public Array { | class Table : public Array { |
| public: | public: |
| Table(Request& arequest, | Table(Pool& apool, |
| char *afile, uint aline, | const String& asource, |
| Array *acolumns, | Array *acolumns, |
| int initial_rows=CR_INITIAL_ROWS_DEFAULT); | int initial_rows=CR_INITIAL_ROWS_DEFAULT); |
| // the base origin of table's data | /// the string source of table's data |
| //const Origin& origin() { return forigin; } | //const String& source() { return fsource; } |
| /// column names | |
| const Array *columns() { return fcolumns; } | const Array *columns() { return fcolumns; } |
| /// moves \a current pointer | |
| void set_current(int acurrent) { fcurrent=acurrent; } | void set_current(int acurrent) { fcurrent=acurrent; } |
| /// @return current pointer | |
| int get_current() { return fcurrent; } | int get_current() { return fcurrent; } |
| void inc_current() { fcurrent++; } | |
| void read_item(String& result, const String& column_name) { | /// @return item from \a column_name |
| result.APPEND(item(column_name), 0/*TODO:think about*/, forigin.file, forigin.line+fcurrent); | const String *item(const String& column_name); |
| } | |
| protected: | private: |
| // the request I'm processed on. for error reporting | |
| Request& request; | |
| // the base origin of table's data | // the base origin of table's data |
| Origin forigin; | const String& fsource; |
| // column name->number lookup table | // column name->number lookup table |
| Hash name2number; | Hash name2number; |
| Line 58 protected: | Line 65 protected: |
| // columns | // columns |
| Array *fcolumns; | Array *fcolumns; |
| bool valid(int index) { return index>=0 && index<size(); } | |
| const Array& at(int index); | const Array& at(int index); |
| const char *item(int column_index); | const String *item(int column_index) { |
| const char *item(const String& column_name); | return valid(fcurrent)?at(fcurrent).get_string(column_index):0; |
| } | |
| }; | }; |
| #endif | #endif |