--- parser3/src/include/pa_table.h 2003/04/11 16:05:43 1.48.2.11.2.8 +++ parser3/src/include/pa_table.h 2003/07/24 11:31:21 1.52 @@ -8,7 +8,7 @@ #ifndef PA_TABLE_H #define PA_TABLE_H -static const char* IDENT_TABLE_H="$Date: 2003/04/11 16:05:43 $"; +static const char* IDENT_TABLE_H="$Date: 2003/07/24 11:31:21 $"; #include "pa_types.h" #include "pa_hash.h" @@ -32,17 +32,6 @@ class Table: public Array public: typedef ArrayString* columns_type; - struct Action_options { - size_t offset; - size_t limit; //< negative limit means 'all'. zero limit means 'nothing' - bool reverse; - bool defined; - - Action_options(): - offset(0), limit(ARRAY_OPTION_LIMIT_ALL), reverse(false), - defined(false) {} - }; - Table( columns_type acolumns, size_t initial_rows=3); @@ -52,7 +41,12 @@ public: columns_type columns() { return fcolumns; } /// moves @a current pointer - void set_current(size_t acurrent); /// @return current pointer + void set_current(size_t acurrent) { + assert(acurrent==0 || acurrent - bool locate(bool (*func)(Table& self, I* info), void* info, Action_options& o) { - size_t count=this->count(); - if(!count || !o.limit) - return false; - if(o.limit==ARRAY_OPTION_LIMIT_ALL) - o.limit=count; + void table_for_each(void (*func)(Table& self, I* info), I* info, Action_options& o) { + if(!o.adjust(count())) + return; + + size_t saved_current=current(); size_t row=o.offset; + if(o.reverse) { // reverse + for(size_t to=row-o.limit; row>=to; --row) { + set_current(row); + func(*this, info); + } + } else { // forward + for(size_t to=row+o.limit; row + bool table_first_that(bool (*func)(Table& self, I* info), void* info, Action_options& o) { + if(!o.adjust(count())) + return false; size_t saved_current=current(); + size_t row=o.offset; if(o.reverse) { // reverse - size_t to=row>o.limit?row-o.limit:0; - for(; row>=to; --row) { + for(size_t to=row-o.limit; row>=to; --row) { set_current(row); if(func(*this, info)) return true; } } else { // forward - size_t to=min(row+o.limit, count); - for(; rownumber lookup table + /// column name->number lookup table typedef Hash name2number_hash_class; name2number_hash_class* name2number; - // we own columns? - + /// is that @c index falid? bool valid(size_t index) const { return index>=0 && index