--- parser3/src/include/pa_table.h 2001/01/29 20:10:32 1.2 +++ parser3/src/include/pa_table.h 2001/03/28 09:01:21 1.25 @@ -1,11 +1,12 @@ -/* - $Id: pa_table.h,v 1.2 2001/01/29 20:10:32 paf Exp $ -*/ +/** @file + Parser: table class decl. -/* - hence most of tables are "named", no need to uptimize unnamed onces -*/ + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: pa_table.h,v 1.25 2001/03/28 09:01:21 paf Exp $ +*/ #ifndef PA_TABLE_H #define PA_TABLE_H @@ -16,34 +17,73 @@ #include "pa_string.h" #include "pa_request.h" -class Table : public Array { -public: - - // request I'm processed on - Request& request; +/** + VTable backend. - // the base origin of table data - Origin origin; + holds: + - column names[if any] + - data rows + - current row pointer - int current; + uses String for column names and data items - // columns - Array *columns; + hence most of tables are "named", no need to uptimize nameless onces +*/ +class Table : public Array { +public: - Table(Request& request, - char *afile, uint aline, + Table(Pool& apool, + const String *aorigin, Array *acolumns, int initial_rows=CR_INITIAL_ROWS_DEFAULT); - char *item(int column_index); - char *item(String column_name); + /// where this table came from, may be NULL + const String *origin_string() { return forigin_string; } + + /// column names + const Array *columns() { return fcolumns; } -protected: + /// moves @a current pointer + void set_current(int acurrent) { fcurrent=acurrent; } + /// @return current pointer + int current() { return fcurrent; } + void shift(int offset); + + /// @return item from @a column_name + const String *item(const String& column) const { + return item(column_name2index(column)); + } + + /// saves to text file + void save(bool nameless_save, const String& file_spec); + + bool locate(const String& column, const String& value); + +private: + + // where this table came from, may be NULL + const String *forigin_string; // column name->number lookup table Hash name2number; - Array *at(int index); + // current row + int fcurrent; + + // columns + Array *fcolumns; + + bool valid(int index) const { return index>=0 && index(static_cast(get(index))); + } + + /// @return column index from @a column_name + int column_name2index(const String& column) const; + + const String *item(int column) const; };