int EvalCommand :: Execute( ALib::CommandLine & cmd ) { GetSkipOptions( cmd ); IOManager io( cmd ); CSVRow row; mDiscardInput = cmd.HasFlag( FLAG_DISCARD ); GetExpressions( cmd ); while( io.ReadCSV( row ) ) { if ( Skip( io, row ) ) { continue; } if ( ! Pass( io, row ) ) { SetParams( row, io ); if ( mDiscardInput ) { row.clear(); } Evaluate( row ); } io.WriteRow( row ); } return 0; }
void PivotCommand :: OutputPivot( IOManager & io ) { CSVRow r; r.push_back( "" ); // corresponds to row header for ( auto col : mCols ) { r.push_back( col ); } io.WriteRow( r ); for( auto row : mRows ) { r.clear(); r.push_back( row ); for ( auto col : mCols ) { ColRow cr( col, row ); SumCount sc = mColRowValMap[ cr ]; if ( mAction == Action::Average ) { r.push_back( ALib::Str( sc.mSum / sc.mCount ) ); } else { r.push_back( ALib::Str( sc.mSum ) ); } } io.WriteRow( r ); } }
void ReadFixedCommand :: MakeRow( const string & line, CSVRow & row ) { row.clear(); unsigned int len = line.size(); for( unsigned int i = 0; i < mFields.size(); i++ ) { if ( mFields[i].first > len ) { row.push_back( "" ); } else { string val = line.substr( mFields[i].first - 1, mFields[i].second ); row.push_back( mTrim ? ALib::RTrim( val ) : val ); } } }
void DSVBase :: BuildCSVRow( const CSVRow & in, CSVRow & out ) const { if ( mFields.size() == 0 ) { out = in; } else { out.clear(); for ( unsigned int i = 0; i < mFields.size(); i++ ) { unsigned int f = mFields[ i ]; if ( f < in.size() ) { out.push_back( in[ f ] ); } else { out.push_back( "" ); } } } }