// Created by Igor Markov, 010123 // This program demonstrates processing of command-line parameters // using the UTIL library. Note: this only works if you have the // code for the UTIL library --- more generic command-line processing // will be covered later // To compile, save into mainCMD.cxx within Proto // and update Makefile to build from mainCMD.cxx instead of main.cxx // Then type make clean; make #include #include "UTIL/paramproc.h" int main(int argc, const char *argv[]) { BoolParam helpRequest("h",argc,argv); // this catches -h on command line UnsignedParam unsNumber("u",argc,argv); // this catches -u IntParam intNumber("i",argc,argv); // this catches -i DoubleParam doubleNumber("d",argc,argv);// this catches -d StringParam testStr("s",argc,argv); // this catches -s NoParams noParams(argc,argv); // this acts as a flag if (helpRequest.found() || noParams.found()) { // print out a help message and exit cout << " This program is an illustration of command-line processing\n" << " Recognized options are: \n" << " -h gives this output\n" << " -u tests processing of unsigned params \n" << " -i tests processing of integer params \n" << " -d tests processing of double params \n" << " -s tests processing of string params " << endl; exit(0); } unsigned uParam=0; if (unsNumber.found()) { uParam=unsNumber; cout << " Found an unsigned : " << uParam << endl; } int iParam=0; if (intNumber.found()) { iParam=intNumber; cout << " Found an integer : " << iParam << endl; } double dParam=0; if (doubleNumber.found()) { dParam=doubleNumber; cout << " Found a double : " << dParam << endl; } if (testStr.found()) cout << " Found a string : " << testStr << endl; }