demo/arg_parser_demo.cc
author deba
Thu, 19 Apr 2007 15:12:59 +0000
changeset 2425 08b64ae5a564
parent 2402 da8eb8f4ea41
child 2492 387f6ff851ef
permissions -rw-r--r--
Helper classs for checking existence of a nested class
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2007
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #include <lemon/arg_parser.h>
    20 
    21 using namespace lemon;
    22 int main(int argc, const char **argv)
    23 {
    24   ArgParser ap(argc,argv);
    25   int i;
    26   std::string s;
    27   double d;
    28   bool b,sil;
    29   bool g1,g2,g3;
    30   ap.refOption("n", "an integer input", i, true)
    31     .refOption("val", "a double input", d)
    32     .synonym("vals","val")
    33     .refOption("name", "a string input", s)
    34     .refOption("f", "a switch", b)
    35     .refOption("nohelp", "", sil)
    36     .refOption("gra","Choise A",g1)
    37     .refOption("grb","Choise B",g2)
    38     .refOption("grc","Choise C",g3)
    39     .optionGroup("gr","gra")
    40     .optionGroup("gr","grb")
    41     .optionGroup("gr","grc")
    42     .mandatoryGroup("gr")
    43     .onlyOneGroup("gr")
    44     .other("infile","The input file")
    45     .other("...");
    46   
    47   ap.parse();
    48 
    49   std::cout << "Parameters of '" << ap.commandName() << "':\n";
    50 
    51   if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
    52   if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
    53   if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
    54   if(ap.given("f")) std::cout << "  -f is given\n";
    55   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
    56 
    57   switch(ap.files().size()) {
    58   case 0:
    59     std::cout << "  No file argument was given.\n";
    60     break;
    61   case 1:
    62     std::cout << "  1 file argument was given. It is:\n";
    63     break;
    64   default:
    65     std::cout << "  "
    66 	      << ap.files().size() << " file arguments were given. They are:\n";
    67   }
    68   for(unsigned int i=0;i<ap.files().size();++i)
    69     std::cout << "    '" << ap.files()[i] << "'\n";
    70   
    71 }