demo/arg_parser_demo.cc
changeset 108 889d0c289d19
parent 85 3453d20a82cd
child 128 7cd965d2257f
equal deleted inserted replaced
0:66be6efb23d5 1:a6cd7c130edd
    18 
    18 
    19 ///\ingroup demos
    19 ///\ingroup demos
    20 ///\file
    20 ///\file
    21 ///\brief Argument parser demo
    21 ///\brief Argument parser demo
    22 ///
    22 ///
    23 /// This example shows how can the argument parser used.
    23 /// This example shows how the argument parser can be used.
    24 ///
    24 ///
    25 /// \include arg_parser.cc
    25 /// \include arg_parser_demo.cc
    26 
    26 
    27 #include <lemon/arg_parser.h>
    27 #include <lemon/arg_parser.h>
    28 
    28 
    29 using namespace lemon;
    29 using namespace lemon;
    30 int main(int argc, const char **argv)
    30 int main(int argc, const char **argv)
    33   int i;
    33   int i;
    34   std::string s;
    34   std::string s;
    35   double d;
    35   double d;
    36   bool b,sil;
    36   bool b,sil;
    37   bool g1,g2,g3;
    37   bool g1,g2,g3;
    38   ap.refOption("n", "an integer input", i, true)
    38   ap.refOption("n", "An integer input.", i, true)
    39     .refOption("val", "a double input", d)
    39     .refOption("val", "A double input.", d)
    40     .synonym("vals","val")
    40     .synonym("vals","val")
    41     .refOption("name", "a string input", s)
    41     .refOption("name", "A string input.", s)
    42     .refOption("f", "a switch", b)
    42     .refOption("f", "A switch.", b)
    43     .refOption("nohelp", "", sil)
    43     .refOption("nohelp", "", sil)
    44     .refOption("gra","Choise A",g1)
    44     .refOption("gra","Choice A",g1)
    45     .refOption("grb","Choise B",g2)
    45     .refOption("grb","Choice B",g2)
    46     .refOption("grc","Choise C",g3)
    46     .refOption("grc","Choice C",g3)
    47     .optionGroup("gr","gra")
    47     .optionGroup("gr","gra")
    48     .optionGroup("gr","grb")
    48     .optionGroup("gr","grb")
    49     .optionGroup("gr","grc")
    49     .optionGroup("gr","grc")
    50     .mandatoryGroup("gr")
    50     .mandatoryGroup("gr")
    51     .onlyOneGroup("gr")
    51     .onlyOneGroup("gr")
    52     .other("infile","The input file")
    52     .other("infile","The input file.")
    53     .other("...");
    53     .other("...");
    54   
    54   
    55   ap.parse();
    55   ap.parse();
    56 
    56 
    57   std::cout << "Parameters of '" << ap.commandName() << "':\n";
    57   std::cout << "Parameters of '" << ap.commandName() << "':\n";
    59   if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
    59   if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
    60   if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
    60   if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
    61   if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
    61   if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
    62   if(ap.given("f")) std::cout << "  -f is given\n";
    62   if(ap.given("f")) std::cout << "  -f is given\n";
    63   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
    63   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
    64 
    64   if(ap.given("gra")) std::cout << "  -gra is given\n";
       
    65   if(ap.given("grb")) std::cout << "  -grb is given\n";
       
    66   if(ap.given("grc")) std::cout << "  -grc is given\n";
       
    67                                      
    65   switch(ap.files().size()) {
    68   switch(ap.files().size()) {
    66   case 0:
    69   case 0:
    67     std::cout << "  No file argument was given.\n";
    70     std::cout << "  No file argument was given.\n";
    68     break;
    71     break;
    69   case 1:
    72   case 1: