COIN-OR::LEMON - Graph Library

source: lemon-1.2/demo/arg_parser_demo.cc @ 206:4e22275a2b52

Last change on this file since 206:4e22275a2b52 was 137:483bc6ed7292, checked in by Alpar Juttner <alpar@…>, 17 years ago

Backout some rubbish from chageset 7cd965d2257f

File size: 2.5 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2008
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///\ingroup demos
20///\file
21///\brief Argument parser demo
22///
23/// This example shows how the argument parser can be used.
24///
25/// \include arg_parser_demo.cc
26
27#include <lemon/arg_parser.h>
28
29using namespace lemon;
30int main(int argc, const char **argv)
31{
32  ArgParser ap(argc,argv);
33  int i;
34  std::string s;
35  double d;
36  bool b,sil;
37  bool g1,g2,g3;
38  ap.refOption("n", "An integer input.", i, true)
39    .refOption("val", "A double input.", d)
40    .doubleOption("val2", "A double input.", d)
41    .synonym("vals","val")
42    .refOption("name", "A string input.", s)
43    .refOption("f", "A switch.", b)
44    .refOption("nohelp", "", sil)
45    .refOption("gra","Choice A",g1)
46    .refOption("grb","Choice B",g2)
47    .refOption("grc","Choice C",g3)
48    .optionGroup("gr","gra")
49    .optionGroup("gr","grb")
50    .optionGroup("gr","grc")
51    .mandatoryGroup("gr")
52    .onlyOneGroup("gr")
53    .other("infile","The input file.")
54    .other("...");
55 
56  ap.parse();
57
58  std::cout << "Parameters of '" << ap.commandName() << "':\n";
59
60  if(ap.given("n")) std::cout << "  Value of -n: " << i << std::endl;
61  if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
62  if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
63  if(ap.given("f")) std::cout << "  -f is given\n";
64  if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << sil << std::endl;
65  if(ap.given("gra")) std::cout << "  -gra is given\n";
66  if(ap.given("grb")) std::cout << "  -grb is given\n";
67  if(ap.given("grc")) std::cout << "  -grc is given\n";
68                                     
69  switch(ap.files().size()) {
70  case 0:
71    std::cout << "  No file argument was given.\n";
72    break;
73  case 1:
74    std::cout << "  1 file argument was given. It is:\n";
75    break;
76  default:
77    std::cout << "  "
78              << ap.files().size() << " file arguments were given. They are:\n";
79  }
80  for(unsigned int i=0;i<ap.files().size();++i)
81    std::cout << "    '" << ap.files()[i] << "'\n";
82 
83}
Note: See TracBrowser for help on using the repository browser.