本文整理汇总了C++中alib::CommandLine类的典型用法代码示例。如果您正苦于以下问题:C++ CommandLine类的具体用法?C++ CommandLine怎么用?C++ CommandLine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: io
int JoinCommand :: Execute( ALib::CommandLine & cmd ) {
Clear();
mKeep = cmd.HasFlag( FLAG_KEEP );
mOuterJoin = cmd.HasFlag( FLAG_OUTERJ );
mInvert = cmd.HasFlag( FLAG_INVERT );
mIgnoreCase = cmd.HasFlag( FLAG_ICASE );
if ( mOuterJoin && mInvert ) {
CSVTHROW( "Cannot have both " << FLAG_OUTERJ
<< " and " << FLAG_INVERT << " flags" );
}
string js = cmd.GetValue( FLAG_COLS );
BuildJoinSpecs( js );
IOManager io( cmd );
unsigned int scount = io.InStreamCount();
if ( scount < 2 ) {
CSVTHROW( "Need at least two input streams" );
}
BuildRowMap( io.CreateStreamParser( scount - 1 ) );
CSVRow row;
for ( unsigned int i = 0; i < scount - 1; i++ ) {
std::unique_ptr <ALib::CSVStreamParser> p( io.CreateStreamParser( i ) );
while( p->ParseNext( row ) ) {
WriteJoinRows( io, row );
}
}
return 0;
}
示例2: io
int TemplateCommand :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
ReadTemplate( cmd );
if ( cmd.HasFlag( FLAG_FNAMES ) ) {
mFileTemplate = cmd.GetValue( FLAG_FNAMES );
}
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( row ) ) {
continue;
}
if ( mFileTemplate.empty() ) {
io.Out() << ReplaceColumns( mTemplate, row );
}
else {
FileOut( row );
}
}
return 0;
}
示例3: cl
int EditCommand :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
for ( int i = 2; i < cmd.Argc(); i++ ) {
if ( cmd.Argv( i ) == FLAG_EDIT ) {
AddSubCmd( cmd.Argv( i + 1 ) );
i++;
}
}
ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
CommaListToIndex( cl, mCols );
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( io, row ) ) {
continue;
}
if ( ! Pass( io, row ) ) {
EditRow( row );
}
io.WriteRow( row );
}
return 0;
}
示例4: cl
void FileSplitCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
mDir = cmd.GetValue( FLAG_FSDIR, DEF_DIR );
mFilePrefix = cmd.GetValue( FLAG_FSPRE, DEF_PREF );
mFileExt= cmd.GetValue( FLAG_FSEXT, DEF_EXT );
ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) );
CommaListToIndex( cl, mColIndex );
mUseFieldNames = cmd.HasFlag( FLAG_USEFLD );
}
示例5: cl
void DateFormatCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
CommaListToIndex( cl, mFields );
string fmt = cmd.GetValue( FLAG_FMT, "" );
if ( ALib::IsEmpty( fmt ) ) {
CSVTHROW( "Empty date format" );
}
BuildFormat( fmt );
}
示例6: ProcessFlags
void AsciiTableCommand :: ProcessFlags( ALib::CommandLine & cmd ) {
mUseLineSep = cmd.HasFlag( FLAG_SEP );
mHeadings = ALib::CommaList( cmd.GetValue( FLAG_HEADER, "" ) );
ALib::CommaList ra = ALib::CommaList( cmd.GetValue( FLAG_RALIGN, "" ) );
CommaListToIndex( ra, mRightAlign );
if ( mHeadings.Size() && mHeadings.At(0) != FILE_HEADER) {
CSVRow r;
for ( unsigned int i = 0; i < mHeadings.Size() ; i++ ) {
r.push_back( mHeadings.At( i ) );
}
AddRow( r );
}
}
示例7: io
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;
}
示例8: io
int DSVReadCommand :: Execute( ALib::CommandLine & cmd ) {
ReadFlags( cmd );
mIsCSV = cmd.HasFlag( FLAG_CSV );
mCollapseSep = cmd.HasFlag( FLAG_CMULTI );
IOManager io( cmd );
CSVRow row;
string line;
while( io.ReadLine( line ) ) {
ParseDSV( line, row );
io.WriteRow( row );
}
return 0;
}
示例9: cl
void FixedCommand :: BuildFields( const ALib::CommandLine & cmd ) {
mFields.clear();
ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) ); // chop into pairs
if ( cl.Size() == 0 ) {
CSVTHROW( "Need fields specified with " << FLAG_COLS << " flag" );
}
for ( unsigned int i = 0; i < cl.Size(); i++ ) {
vector <string> tmp;
if ( ALib::Split( cl.At(i), ':', tmp ) != 2 ) {
CSVTHROW( "Invalid field specification: " << cl.At(i) );
}
if ( ! ALib::IsInteger( tmp[0] ) || ! ALib::IsInteger( tmp[1] ) ) {
CSVTHROW( "Invalid field specification: " << cl.At(i) );
}
unsigned int f1 = ALib::ToInteger( tmp[0] );
unsigned int f2 = ALib::ToInteger( tmp[1] );
if ( f1 == 0 || f2 == 0 ) {
CSVTHROW( "Invalid field specification: " << cl.At(i) );
}
mFields.push_back( std::make_pair( f1, f2 ) );
}
}
示例10: cl
void CallCommand :: ProcessFlags( const ALib::CommandLine & cmd ) {
string bs = cmd.GetValue( FLAG_BSIZE, ALib::Str( DEF_OUTBUF_SIZE ) );
if ( ! ALib::IsInteger( bs )) {
CSVTHROW( "Value for buffer size must be integer" );
}
mOutBufSize = ALib::ToInteger( bs ) * 1024;
if ( mOutBufSize < DEF_OUTBUF_SIZE ) {
CSVTHROW( "Output buffer size too small" );
}
mDLL = cmd.GetValue( FLAG_DLL );
mFuncName = cmd.GetValue( FLAG_FUNC );
ALib::CommaList cl( cmd.GetValue( FLAG_COLS ) );
CommaListToIndex( cl, mFields );
}
示例11: cl
void SQLCommand :: BuildCols( const ALib::CommandLine & cmd,
const string & flag,
SQLColSpec::Vec & cols ) {
bool havenames = false;
cols.clear();
if ( cmd.FlagCount( flag ) > 1 ) {
CSVTHROW( "Need fields specified by single " << flag << " flag" );
}
ALib::CommaList cl( cmd.GetValue( flag ) );
for ( unsigned int i = 0; i < cl.Size(); i++ ) {
vector <string> tmp;
if ( ALib::Split( cl.At(i), ':', tmp ) > 2 ) {
CSVTHROW( "Invalid column specification: " << cl.At(i) );
}
if ( tmp.size() == 0 ) {
CSVTHROW( "Empty column specification" );
}
if ( ! ALib::IsInteger( tmp[0] ) ) {
CSVTHROW( "Field index must be integer in " << cl.At(i) );
}
int icol = ALib::ToInteger( tmp[0] );
if ( icol <= 0 ) {
CSVTHROW( "Field index must be greater than xero in " << cl.At(i) );
}
if ( tmp.size() == 1 && havenames ) {
CSVTHROW( "Must specify all column names" );
}
havenames = havenames || tmp.size() == 2;
string colname = tmp.size() == 2 ? tmp[1] : string("");
cols.push_back( SQLColSpec( icol - 1, colname ) );
}
}
示例12: cl
int TrimCommand :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
if ( cmd.HasFlag( FLAG_TRLEAD ) || cmd.HasFlag( FLAG_TRTRAIL ) ) {
mTrimLead = cmd.HasFlag( FLAG_TRLEAD );
mTrimTrail = cmd.HasFlag( FLAG_TRTRAIL );
}
else {
mTrimLead = mTrimTrail = true;
}
if ( cmd.HasFlag( FLAG_WIDTH ) ) {
GetWidths( cmd.GetValue( FLAG_WIDTH ) );
}
ALib::CommaList cl( cmd.GetValue( FLAG_COLS, "" ) );
CommaListToIndex( cl, mFields );
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( row ) ) {
continue;
}
if ( ! Pass( row ) ) {
Trim( row );
}
io.WriteRow( row );
}
return 0;
}
示例13: GetCommonValues
void SQLCommand :: GetCommonValues( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
mTable = cmd.GetValue( FLAG_TABLE );
if ( mTable == "" ) {
CSVTHROW( "Need table name specified by " << FLAG_TABLE << " flag" );
}
if ( ! cmd.HasFlag( FLAG_SQLSEP ) ) {
mSep ="\n;\n";
}
else {
mSep = ALib::UnEscape( cmd.GetValue( FLAG_SQLSEP ) );
}
string noq = cmd.GetValue( FLAG_NOQUOTE, "" );
if ( ! ALib::IsEmpty( noq ) ) {
CommaListToIndex( ALib::CommaList( noq ), mNoQuote );
}
mQuoteNulls = cmd.HasFlag( FLAG_QNULLS );
mEmptyNulls = cmd.HasFlag( FLAG_ENULLS );
}
示例14: GetField
static unsigned int GetField( const ALib::CommandLine & cmd,
const string & option ) {
string rc = cmd.GetValue( option );
if ( ! ALib::IsInteger( rc ) ) {
CSVTHROW( "Value for " << option << " must be integer" );
}
int n = ALib::ToInteger( rc );
if ( n <= 0 ) {
CSVTHROW( "Value for " << option << " must be greater than zero" );
}
return (unsigned int) n - 1;
}
示例15: padding
int TruncPadBase :: Execute( ALib::CommandLine & cmd ) {
GetSkipOptions( cmd );
string ps = cmd.GetValue( FLAG_PAD );
ALib::CommaList padding( ps );
unsigned int ncols = padding.Size();
bool ncolspec = false; // use explicit size or not
if ( ncols == 0 || cmd.HasFlag( FLAG_NUM ) ) {
if ( ! cmd.HasFlag( FLAG_NUM ) ) {
CSVTHROW( "Need -n flag to specify field count" );
}
ncolspec = true;
string nv = cmd.GetValue( FLAG_NUM );
if ( ALib::ToInteger( nv, "-n flag needs integer value" ) < 0 ) {
CSVTHROW( FLAG_NUM << " needs value greater or equal to zero" );
}
ncols = ALib::ToInteger( nv );
}
IOManager io( cmd );
CSVRow row;
while( io.ReadCSV( row ) ) {
if ( Skip( io, row ) ) {
continue;
}
if ( ! Pass( io, row ) ) {
unsigned int nc = ncolspec ? ncols : row.size() + padding.Size();
ProcessRow( row, nc, padding );
}
io.WriteRow( row );
}
return 0;
}