demo/arg_parser_demo.cc
author kpeter
Thu, 13 Nov 2008 16:17:50 +0000
changeset 2630 d239741cfd44
parent 2492 387f6ff851ef
permissions -rw-r--r--
Various improvements in NetworkSimplex.

- Faster variant of "Altering Candidate List" pivot rule using make_heap
instead of partial_sort.
- Doc improvements.
- Removing unecessary inline keywords.
alpar@2391
     1
/* -*- C++ -*-
alpar@2391
     2
 *
alpar@2391
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@2391
     4
 *
alpar@2553
     5
 * Copyright (C) 2003-2008
alpar@2391
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@2391
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@2391
     8
 *
alpar@2391
     9
 * Permission to use, modify and distribute this software is granted
alpar@2391
    10
 * provided that this copyright notice appears in all copies. For
alpar@2391
    11
 * precise terms see the accompanying LICENSE file.
alpar@2391
    12
 *
alpar@2391
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@2391
    14
 * express or implied, and with no claim as to its suitability for any
alpar@2391
    15
 * purpose.
alpar@2391
    16
 *
alpar@2391
    17
 */
alpar@2391
    18
deba@2492
    19
///\ingroup demos
deba@2492
    20
///\file
deba@2492
    21
///\brief Argument parser demo
deba@2492
    22
///
deba@2492
    23
/// This example shows how can the argument parser used.
deba@2492
    24
///
deba@2492
    25
/// \include arg_parser.cc
deba@2492
    26
alpar@2389
    27
#include <lemon/arg_parser.h>
alpar@2389
    28
alpar@2389
    29
using namespace lemon;
deba@2411
    30
int main(int argc, const char **argv)
alpar@2389
    31
{
alpar@2389
    32
  ArgParser ap(argc,argv);
alpar@2389
    33
  int i;
alpar@2389
    34
  std::string s;
alpar@2389
    35
  double d;
alpar@2389
    36
  bool b,sil;
alpar@2389
    37
  bool g1,g2,g3;
alpar@2402
    38
  ap.refOption("n", "an integer input", i, true)
alpar@2402
    39
    .refOption("val", "a double input", d)
alpar@2389
    40
    .synonym("vals","val")
alpar@2402
    41
    .refOption("name", "a string input", s)
alpar@2402
    42
    .refOption("f", "a switch", b)
alpar@2402
    43
    .refOption("nohelp", "", sil)
alpar@2402
    44
    .refOption("gra","Choise A",g1)
alpar@2402
    45
    .refOption("grb","Choise B",g2)
alpar@2402
    46
    .refOption("grc","Choise C",g3)
alpar@2389
    47
    .optionGroup("gr","gra")
alpar@2389
    48
    .optionGroup("gr","grb")
alpar@2389
    49
    .optionGroup("gr","grc")
alpar@2389
    50
    .mandatoryGroup("gr")
alpar@2389
    51
    .onlyOneGroup("gr")
alpar@2389
    52
    .other("infile","The input file")
alpar@2389
    53
    .other("...");
alpar@2389
    54
  
alpar@2389
    55
  ap.parse();
alpar@2389
    56
alpar@2389
    57
  std::cout << "Parameters of '" << ap.commandName() << "':\n";
alpar@2389
    58
alpar@2389
    59
  if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
alpar@2389
    60
  if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
alpar@2389
    61
  if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
alpar@2389
    62
  if(ap.given("f")) std::cout << "  -f is given\n";
alpar@2389
    63
  if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
alpar@2389
    64
alpar@2389
    65
  switch(ap.files().size()) {
alpar@2389
    66
  case 0:
alpar@2389
    67
    std::cout << "  No file argument was given.\n";
alpar@2389
    68
    break;
alpar@2389
    69
  case 1:
alpar@2389
    70
    std::cout << "  1 file argument was given. It is:\n";
alpar@2389
    71
    break;
alpar@2389
    72
  default:
alpar@2389
    73
    std::cout << "  "
alpar@2389
    74
	      << ap.files().size() << " file arguments were given. They are:\n";
alpar@2389
    75
  }
alpar@2389
    76
  for(unsigned int i=0;i<ap.files().size();++i)
alpar@2389
    77
    std::cout << "    '" << ap.files()[i] << "'\n";
alpar@2389
    78
  
alpar@2389
    79
}