Diff for /parser3/src/main/pa_table.C between versions 1.25 and 1.50

version 1.25, 2001/04/04 10:50:36 version 1.50, 2002/08/06 14:23:23
Line 1 Line 1
 /** @file  /** @file
         Parser: table class.          Parser: table class.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
           Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)  
   
         $Id$  
 */  */
   
 #include <stdlib.h>  static const char* IDENT_TABLE_C="$Date$";
   
   //#include <stdlib.h>
   
 #include "pa_table.h"  #include "pa_table.h"
 #include "pa_pool.h"  #include "pa_pool.h"
Line 16 Line 15
   
 Table::Table(Pool& apool,   Table::Table(Pool& apool, 
                          const String *aorigin_string,                           const String *aorigin_string,
                          Array *acolumns,                            const Array *acolumns, 
                          int initial_rows) :                           int initial_rows) :
         Array(apool, initial_rows),          Array(apool, initial_rows),
   
         forigin_string(aorigin_string),          forigin_string(aorigin_string),
         fcurrent(0),          fcurrent(0),
         fcolumns(acolumns),           fcolumns(acolumns), 
         name2number(pool(), false) {          name2number(*NEW Hash(pool())) {
   
         if(fcolumns)          if(fcolumns)
                 for(int i=0; i<fcolumns->size(); i++) {                  for(int i=0; i<fcolumns->size(); i++) {
Line 32  Table::Table(Pool& apool, Line 31  Table::Table(Pool& apool,
                 }                  }
 }  }
   
 int Table::column_name2index(const String& column_name) const {  Table::Table(Pool& apool, const Table& source, int offset, int limit) :
         if(fcolumns) { // named          Array(apool, limit/*may be more than needed, no harm done*/),
                 int column_number=name2number.get_int(column_name);  
                 if(column_number)          forigin_string(source.forigin_string),
                         return column_number-1;          fcurrent(source.fcurrent),
                 else {          fcolumns(source.fcolumns),
                         THROW(0, 0,          name2number(source.name2number) {
                                 &column_name,   
           append_array(source, offset, limit);
   }
   
   int Table::column_name2index(const String& column_name, bool bark) const {
           if(fcolumns) {// named
                   int result=name2number.get_int(column_name)-1; // -1 = column not found
                   if(bark && result<0)
                           throw Exception("parser.runtime",
                                   &column_name,
                                 "column not found");                                  "column not found");
                         return 0; // unreached                  return result;
                 }  
         } else { // nameless          } else { // nameless
                 char *error_pos=0;                  char *error_pos;
                 int result=(int)strtol(column_name.cstr(), &error_pos, 0);                  const char *cstr=column_name.cstr();
                 if(error_pos && *error_pos)                  int result=(int)strtol(cstr, &error_pos, 0);
                         THROW(0, 0,                  if(*error_pos/*not EOS*/) {
                                 &column_name,                          result=-1;
                                 "invalid column number");                          if(bark)
                                   throw Exception("parser.runtime",
                                           &column_name,
                                           "invalid column number");
                   }
                 return result;                  return result;
         }          }
 }  }
Line 64  const String *Table::item(int column) co Line 75  const String *Table::item(int column) co
 }  }
   
 bool Table::locate(int column, const String& value) {  bool Table::locate(int column, const String& value) {
           int scurrent=fcurrent;
         for(fcurrent=0; fcurrent<size(); fcurrent++) {          for(fcurrent=0; fcurrent<size(); fcurrent++) {
                 const String *item_value=item(column);                  const String *item_value=item(column);
                 if(item_value && *item_value==value)                  if(item_value && *item_value==value)
                         return true;                          return true;
         }          }
   
         fcurrent=0;          fcurrent=scurrent;
         return false;          return false;
 }  }
   
 void Table::shift(int offset) {  bool Table::locate(const String& column, const String& value) {
           return locate(column_name2index(column, true), value);
   }
   
   void Table::offset(bool absolute, int offset) {
         if(size())          if(size())
                 fcurrent=(fcurrent+offset+size())%size();                  fcurrent=((absolute?0:fcurrent)+offset+size())%size();
 }  }

Removed from v.1.25  
changed lines
  Added in v.1.50


E-mail: