Diff for /parser3/src/classes/table.C between versions 1.188 and 1.201

version 1.188, 2003/11/04 12:04:39 version 1.201, 2004/04/01 15:08:48
Line 1 Line 1
 /** @file  /** @file
         Parser: @b table parser class.          Parser: @b table parser class.
   
         Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
 static const char* IDENT_TABLE_C="$Date$";  static const char * const IDENT_TABLE_C="$Date$";
   
 #include "classes.h"  #include "classes.h"
 #include "pa_vmethod_frame.h"  #include "pa_vmethod_frame.h"
Line 21  static const char* IDENT_TABLE_C="$Date$ Line 21  static const char* IDENT_TABLE_C="$Date$
   
 class MTable: public Methoded {  class MTable: public Methoded {
 public: // VStateless_class  public: // VStateless_class
         Value* create_new_value() { return new VTable(); }          Value* create_new_value(Pool&) { return new VTable(); }
   
 public:  public:
         MTable();          MTable();
Line 178  static void _create(Request& r, MethodPa Line 178  static void _create(Request& r, MethodPa
         GET_SELF(r, VTable).set_table(table);          GET_SELF(r, VTable).set_table(table);
 }  }
   
 static char* remove_encloser(char* cstr, char encloser) {  
         if(cstr[0]!=encloser)  
                 return cstr;  
   
         size_t length=strlen(cstr);  
         if(length<2 || cstr[length-1]!=encloser)  
                 return cstr;  
   
         // 'string'  
   
         cstr[length-1]=0;  
         cstr++;  
   
         // double-encloser stands for encloser  
         char *read;  
         char *write;  
         write=read=cstr;  
         while(char c=*read++) {  
                 if(c==encloser && *read==encloser)  
                         read++;  
   
                 *write++=c;  
         }  
         *write=0; // terminate  
   
         return cstr;  
 }  
   
 struct lsplit_result {  struct lsplit_result {
         char* piece;          char* piece;
         char delim;          char delim;
Line 249  static lsplit_result lsplit(char** strin Line 221  static lsplit_result lsplit(char** strin
                         char *write;                          char *write;
                         write=read=string;                          write=read=string;
                         char c;                          char c;
                         while(c=*read++) {                          while((c=*read++)) {
                                 if(c==encloser) {                                  if(c==encloser) {
                                         char n=*read;                                          char n=*read;
                                         if(n==encloser) // double-encloser stands for encloser                                          if(n==encloser) // double-encloser stands for encloser
Line 279  static void skip_empty_and_comment_lines Line 251  static void skip_empty_and_comment_lines
                 while( char c=*data ) {                  while( char c=*data ) {
                         if( c== '\n' || c == '#' ) {                          if( c== '\n' || c == '#' ) {
                                 /*nowhere=*/getrow(&data); // remove empty&comment lines                                  /*nowhere=*/getrow(&data); // remove empty&comment lines
                                 *data_ref=data;                                  if(!(*data_ref=data))
                                           break;
                                 continue;                                  continue;
                         }                          }
                         break;                          break;
Line 363  static void _load(Request& r, MethodPara Line 336  static void _load(Request& r, MethodPara
         Table::element_type row(new ArrayString);          Table::element_type row(new ArrayString);
         skip_empty_and_comment_lines(&data);          skip_empty_and_comment_lines(&data);
         while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) {          while( lsplit_result sr=lsplit(&data, separators.column, '\n', separators.encloser) ) {
                 if(!sr.delim && !row->count()) // append last empty column [if without \n]                  if(!*sr.piece && !sr.delim && !row->count()) // append last empty column [if without \n]
                         break;                          break;
                 *row+=new String(sr.piece, 0, true);                  *row+=new String(sr.piece, 0, true);
                 if(sr.delim=='\n') {                  if(sr.delim=='\n') {
Line 384  static void maybe_enclose( String& to, c Line 357  static void maybe_enclose( String& to, c
         if(encloser) {          if(encloser) {
                 to<<*sencloser;                  to<<*sencloser;
                 // while we have 'encloser'...                  // while we have 'encloser'...
                 for( size_t pos_before, pos_after=0; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; ) {                  size_t pos_after=0;
                   for( size_t pos_before; (pos_before=from.pos( encloser, pos_after ))!=STRING_NOT_FOUND; pos_after=pos_before+1) {
             to<<from.mid(pos_before+1/*+found encloser*/, pos_after-pos_before);              to<<from.mid(pos_before+1/*+found encloser*/, pos_after-pos_before);
                         to<<*sencloser; // doubling encloser                          to<<*sencloser; // doubling encloser
                         pos_after=pos_before+1;  
                 }                  }
                 // last piece                  // last piece
                 size_t from_length=from.length();                  size_t from_length=from.length();
Line 657  static void _hash(Request& r, MethodPara Line 630  static void _hash(Request& r, MethodPara
                                 } else                                  } else
                                         throw Exception("parser.runtime",                                          throw Exception("parser.runtime",
                                                 0,                                                  0,
                                                 "value field(s) must be string or self_table"                                                  "value field(s) must be string or table"
                                         );                                          );
                         } else { // by all columns, including key                          } else { // by all columns, including key
                                 if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST))                                  if(!(distinct!=D_ILLEGAL && distinct!=D_FIRST))
Line 667  static void _hash(Request& r, MethodPara Line 640  static void _hash(Request& r, MethodPara
   
   
                         {                          {
                                 Row_info info={0};  
                                 info.r=&r;  
                                 info.table=&self_table;  
                                 Value* key_param=&params[0];                                  Value* key_param=&params[0];
                                 info.key_code=key_param->get_junction()?key_param:0;                                  Row_info info={
                                 info.key_field=info.key_code?-1                                          &r,
                                         :self_table.column_name2index(key_param->as_string(), true);                                          &self_table,
                                 info.value_fields=&value_fields;                                          /*key_code=*/key_param->get_junction()?key_param:0,
                                 info.hash=&result.hash();                                          /*key_field=*/0/*filled below*/,
                                 info.distinct=distinct;                                          &value_fields,
                                 info.row=0;                                          &result.hash(),
                                           distinct,
                                           /*row=*/0
                                   };
                                   info.key_field=(info.key_code?-1
                                                   :self_table.column_name2index(key_param->as_string(), true));
   
                                 int saved_current=self_table.current();                                  int saved_current=self_table.current();
                                 self_table.for_each(table_row_to_hash, &info);                                  self_table.for_each(table_row_to_hash, &info);
Line 761  struct Expression_is_true_info { Line 736  struct Expression_is_true_info {
         Value* expression_code;          Value* expression_code;
 };  };
 #endif  #endif
 static bool expression_is_true(Table& self, void* ainfo) {  static bool expression_is_true(Table&, Expression_is_true_info* info) {
         Expression_is_true_info& info=*static_cast<Expression_is_true_info*>(ainfo);          return info->r->process_to_value(*info->expression_code).as_bool();
         return info.r->process_to_value(*info.expression_code).as_bool();  
 }  }
 static bool _locate_expression(Table& table, Table::Action_options o,  static bool _locate_expression(Table& table, Table::Action_options o,
                                Request& r, MethodParams& params) {                                 Request& r, MethodParams& params) {
Line 775  static bool _locate_expression(Table& ta Line 749  static bool _locate_expression(Table& ta
         return table.table_first_that(expression_is_true, &info, o);          return table.table_first_that(expression_is_true, &info, o);
 }  }
 static bool _locate_name_value(Table& table, Table::Action_options o,  static bool _locate_name_value(Table& table, Table::Action_options o,
                                Request& r, MethodParams& params) {                                 Request&, MethodParams& params) {
         check_option_param(o.defined, params, 2,          check_option_param(o.defined, params, 2,
                 "locate by locate by name has parameters: name, value and, maybe, options");                  "locate by locate by name has parameters: name, value and, maybe, options");
         const String& name=params.as_string(0, "column name must be string");          const String& name=params.as_string(0, "column name must be string");
Line 794  static void _locate(Request& r, MethodPa Line 768  static void _locate(Request& r, MethodPa
 }  }
   
   
 static void _flip(Request& r, MethodParams& params) {  static void _flip(Request& r, MethodParams&) {
         Table& old_table=GET_SELF(r, VTable).table();          Table& old_table=GET_SELF(r, VTable).table();
         Table& new_table=*new Table(0);          Table& new_table=*new Table(0);
         if(size_t old_count=old_table.count())          if(size_t old_count=old_table.count())
Line 855  static void _join(Request& r, MethodPara Line 829  static void _join(Request& r, MethodPara
                         0,                           0, 
                         "source and destination are same table");                          "source and destination are same table");
   
         if(Table::columns_type dest_columns=dest.columns()) // dest is named          if(dest.columns()) // dest is named
                 src.table_for_each(join_named_row, &dest, o);                  src.table_for_each(join_named_row, &dest, o);
         else // dest is nameless          else // dest is nameless
                 src.table_for_each(join_nameless_row, &dest, o);                  src.table_for_each(join_nameless_row, &dest, o);
Line 1005  static void _select(Request& r, MethodPa Line 979  static void _select(Request& r, MethodPa
                 source_table.set_current(row);                  source_table.set_current(row);
   
                 bool condition=r.process_to_value(vcondition,                   bool condition=r.process_to_value(vcondition, 
                                 /*0/*no name* /,*/  
                                 false/*don't intercept string*/).as_bool();                                  false/*don't intercept string*/).as_bool();
   
                 if(condition) // ...condition is true=                  if(condition) // ...condition is true=

Removed from v.1.188  
changed lines
  Added in v.1.201


E-mail: