--- parser3/src/include/pa_table.h 2001/01/29 20:10:32 1.2 +++ parser3/src/include/pa_table.h 2001/03/29 20:53:03 1.27 @@ -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.27 2001/03/29 20:53:03 paf Exp $ +*/ #ifndef PA_TABLE_H #define PA_TABLE_H @@ -16,34 +17,77 @@ #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; } -protected: + /// column names + const Array *columns() { return fcolumns; } + + /// 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 + const String *item(int column) const; + /// @return item from @a column + 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(int column, const String& value); + bool locate(const String& column, const String& value) { + return locate(column_name2index(column), value); + } + + const Array& at(int index) const { + // force @c const result + return *const_cast(static_cast(get(index))); + } + +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