gtestCmdLnArg.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program gtestCmdLnArg
5 
6 \brief Program used for testing the command line argument parser
7 
8 \author Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
9  University of Liverpool & STFC Rutherford Appleton Laboratory
10 
11 \created July 23, 2010
12 
13 \cpright Copyright (c) 2003-2020, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 
16 */
17 //____________________________________________________________________________
18 
19 #include <string>
20 #include <vector>
21 
24 
25 using std::string;
26 using std::vector;
27 
28 using namespace genie;
29 
30 int main(int argc, char **argv)
31 {
32  CmdLnArgParser parser(argc,argv);
33 
34  LOG("test", pNOTICE)
35  << "Option -f exists? " << parser.OptionExists('f');
36  LOG("test", pNOTICE)
37  << "Option -s exists? " << parser.OptionExists('s');
38 
39  if(parser.OptionExists('d')) {
40  LOG("test", pNOTICE)
41  << "Command line argument following -d : "
42  << parser.Arg('d');
43  LOG("test", pNOTICE)
44  << "Command line argument following -d (as double): "
45  << parser.ArgAsDouble('d');
46  }
47 
48  if(parser.OptionExists('l')) {
49  LOG("test", pNOTICE)
50  << "Command line argument following -l : "
51  << parser.Arg('l');
52  LOG("test", pNOTICE)
53  << "Command line argument following -l (as long int): "
54  << parser.ArgAsLong('l');
55  }
56 
57  if(parser.OptionExists('v')) {
58  LOG("test", pNOTICE)
59  << "Command line argument following -v : "
60  << parser.Arg('v');
61  vector<string> tokens = parser.ArgAsStringTokens('v',",");
62  vector<string>::const_iterator iter = tokens.begin();
63  for( ; iter != tokens.end(); ++iter) {
64  LOG("test", pNOTICE)
65  << "Token: " << *iter;
66  }
67  }
68 
69  if(parser.OptionExists("with-long-command-line-option")) {
70  LOG("test", pNOTICE)
71  << "Command line argument following --with-long-command-line-option : "
72  << parser.Arg("with-long-command-line-option");
73  }
74 
75  return 0;
76 }
77 //____________________________________________________________________________
long ArgAsLong(char opt)
double ArgAsDouble(char opt)
vector< string > ArgAsStringTokens(char opt, string delimeter)
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
std::string string
Definition: nybbler.cc:12
int main(int argc, char **argv)
struct vector vector
intermediate_table::const_iterator const_iterator
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
bool OptionExists(char opt)
was option set?
char * Arg(char opt)
return argument following -`opt&#39;