demo/arg_parser_demo.cc
author deba
Thu, 19 Apr 2007 15:14:34 +0000
changeset 2426 6e1027a05d73
parent 2402 da8eb8f4ea41
child 2492 387f6ff851ef
permissions -rw-r--r--
Allowing 'string' type quoting
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@2391
     5
 * Copyright (C) 2003-2007
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
alpar@2389
    19
#include <lemon/arg_parser.h>
alpar@2389
    20
alpar@2389
    21
using namespace lemon;
deba@2411
    22
int main(int argc, const char **argv)
alpar@2389
    23
{
alpar@2389
    24
  ArgParser ap(argc,argv);
alpar@2389
    25
  int i;
alpar@2389
    26
  std::string s;
alpar@2389
    27
  double d;
alpar@2389
    28
  bool b,sil;
alpar@2389
    29
  bool g1,g2,g3;
alpar@2402
    30
  ap.refOption("n", "an integer input", i, true)
alpar@2402
    31
    .refOption("val", "a double input", d)
alpar@2389
    32
    .synonym("vals","val")
alpar@2402
    33
    .refOption("name", "a string input", s)
alpar@2402
    34
    .refOption("f", "a switch", b)
alpar@2402
    35
    .refOption("nohelp", "", sil)
alpar@2402
    36
    .refOption("gra","Choise A",g1)
alpar@2402
    37
    .refOption("grb","Choise B",g2)
alpar@2402
    38
    .refOption("grc","Choise C",g3)
alpar@2389
    39
    .optionGroup("gr","gra")
alpar@2389
    40
    .optionGroup("gr","grb")
alpar@2389
    41
    .optionGroup("gr","grc")
alpar@2389
    42
    .mandatoryGroup("gr")
alpar@2389
    43
    .onlyOneGroup("gr")
alpar@2389
    44
    .other("infile","The input file")
alpar@2389
    45
    .other("...");
alpar@2389
    46
  
alpar@2389
    47
  ap.parse();
alpar@2389
    48
alpar@2389
    49
  std::cout << "Parameters of '" << ap.commandName() << "':\n";
alpar@2389
    50
alpar@2389
    51
  if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
alpar@2389
    52
  if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
alpar@2389
    53
  if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
alpar@2389
    54
  if(ap.given("f")) std::cout << "  -f is given\n";
alpar@2389
    55
  if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
alpar@2389
    56
alpar@2389
    57
  switch(ap.files().size()) {
alpar@2389
    58
  case 0:
alpar@2389
    59
    std::cout << "  No file argument was given.\n";
alpar@2389
    60
    break;
alpar@2389
    61
  case 1:
alpar@2389
    62
    std::cout << "  1 file argument was given. It is:\n";
alpar@2389
    63
    break;
alpar@2389
    64
  default:
alpar@2389
    65
    std::cout << "  "
alpar@2389
    66
	      << ap.files().size() << " file arguments were given. They are:\n";
alpar@2389
    67
  }
alpar@2389
    68
  for(unsigned int i=0;i<ap.files().size();++i)
alpar@2389
    69
    std::cout << "    '" << ap.files()[i] << "'\n";
alpar@2389
    70
  
alpar@2389
    71
}