demo/arg_parser_demo.cc
changeset 296 9768e60aa4e1
parent 204 77d56a21c3ab
child 311 c887e703b566
equal deleted inserted replaced
4:bbf0ebcf7131 5:76973f8122c5
     1 /* -*- C++ -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2008
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
    62   // Set the options of the group exclusive (only one option can be given)
    62   // Set the options of the group exclusive (only one option can be given)
    63   ap.onlyOneGroup("gr");
    63   ap.onlyOneGroup("gr");
    64   // Add non-parsed arguments (e.g. input files)
    64   // Add non-parsed arguments (e.g. input files)
    65   ap.other("infile", "The input file.")
    65   ap.other("infile", "The input file.")
    66     .other("...");
    66     .other("...");
    67   
    67 
    68   // Perform the parsing process
    68   // Perform the parsing process
    69   // (in case of any error it terminates the program)
    69   // (in case of any error it terminates the program)
    70   ap.parse();
    70   ap.parse();
    71 
    71 
    72   // Check each option if it has been given and print its value
    72   // Check each option if it has been given and print its value
    82   if(ap.given("f")) std::cout << "  -f is given\n";
    82   if(ap.given("f")) std::cout << "  -f is given\n";
    83   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << nh << std::endl;
    83   if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << nh << std::endl;
    84   if(ap.given("gra")) std::cout << "  -gra is given\n";
    84   if(ap.given("gra")) std::cout << "  -gra is given\n";
    85   if(ap.given("grb")) std::cout << "  -grb is given\n";
    85   if(ap.given("grb")) std::cout << "  -grb is given\n";
    86   if(ap.given("grc")) std::cout << "  -grc is given\n";
    86   if(ap.given("grc")) std::cout << "  -grc is given\n";
    87   
    87 
    88   switch(ap.files().size()) {
    88   switch(ap.files().size()) {
    89   case 0:
    89   case 0:
    90     std::cout << "  No file argument was given.\n";
    90     std::cout << "  No file argument was given.\n";
    91     break;
    91     break;
    92   case 1:
    92   case 1:
    93     std::cout << "  1 file argument was given. It is:\n";
    93     std::cout << "  1 file argument was given. It is:\n";
    94     break;
    94     break;
    95   default:
    95   default:
    96     std::cout << "  "
    96     std::cout << "  "
    97 	      << ap.files().size() << " file arguments were given. They are:\n";
    97               << ap.files().size() << " file arguments were given. They are:\n";
    98   }
    98   }
    99   for(unsigned int i=0;i<ap.files().size();++i)
    99   for(unsigned int i=0;i<ap.files().size();++i)
   100     std::cout << "    '" << ap.files()[i] << "'\n";
   100     std::cout << "    '" << ap.files()[i] << "'\n";
   101   
   101 
   102   return 0;
   102   return 0;
   103 }
   103 }