#include <animal/argumentParser.h>
using std::istream;
using std::ifstream;
using std::ostream;
using std::cout;
using std::cerr;
using std::cin;
using std::endl;
struct MyComplex {
double real, imaginary;
MyComplex( double r=0, double i=0 ): real(r), imaginary(i) {}
};
ostream& operator << ( ostream& str, const MyComplex& c ) {
str << c.real << " " << c.imaginary;
return str;
}
istream& operator >> ( istream& str, MyComplex& c ) {
str >> c.real >> c.imaginary;
return str;
}
main( int argc, char* argv[] )
{
if( argc<2 ){
cerr<<"usage: cmdFile <file> [file...]"<<endl;
exit(1);
}
double d=2.2;
int i=0;
MyComplex c;
bool f1=false;
bool f2=false;
animal::ArgumentParser parse("This is a test program \
for the Argumentparser class. This parser allows you to easily parse a command \
line including short or long names for arguments. Short names start with prefix - and \
consist of one character. They can be concatenated, e.g. -ifd. Long names start with \
prefix -- and can not be concatenated.");
parse
.parameter( &d, 'd', "double", "what my double means" )
.option( &i, 0, "int", "what my integer means" )
.parameter( &c, 'c', "cplx", "what my complex means" )
.option( &f1, 'f', "flag1", "what my first flag means" )
.option( &f2, 'g', "flag2", "what my second flag means" );
for( int i=1; i<argc; ++i ){
ifstream in(argv[i]);
if( !in )
{
cerr << "Could not open file " << argv[i] << endl;
exit(1);
}
parse( in );
}
cout << "d = " << d << endl;
cout << "i = " << i << endl;
cout << "c = " << c << endl;
if( f1 ) cout << "flag 1 is set" << endl;
if( f2 ) cout << "flag 2 is set" << endl;
}