alpar@85: /* -*- C++ -*- alpar@85: * alpar@85: * This file is a part of LEMON, a generic C++ optimization library alpar@85: * alpar@85: * Copyright (C) 2003-2008 alpar@85: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@85: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@85: * alpar@85: * Permission to use, modify and distribute this software is granted alpar@85: * provided that this copyright notice appears in all copies. For alpar@85: * precise terms see the accompanying LICENSE file. alpar@85: * alpar@85: * This software is provided "AS IS" with no warranty of any kind, alpar@85: * express or implied, and with no claim as to its suitability for any alpar@85: * purpose. alpar@85: * alpar@85: */ alpar@85: alpar@85: ///\ingroup demos alpar@85: ///\file alpar@85: ///\brief Argument parser demo alpar@85: /// alpar@85: /// This example shows how can the argument parser used. alpar@85: /// alpar@85: /// \include arg_parser.cc alpar@85: alpar@85: #include alpar@85: alpar@85: using namespace lemon; alpar@85: int main(int argc, const char **argv) alpar@85: { alpar@85: ArgParser ap(argc,argv); alpar@85: int i; alpar@85: std::string s; alpar@85: double d; alpar@85: bool b,sil; alpar@85: bool g1,g2,g3; alpar@85: ap.refOption("n", "an integer input", i, true) alpar@85: .refOption("val", "a double input", d) alpar@85: .synonym("vals","val") alpar@85: .refOption("name", "a string input", s) alpar@85: .refOption("f", "a switch", b) alpar@85: .refOption("nohelp", "", sil) alpar@85: .refOption("gra","Choise A",g1) alpar@85: .refOption("grb","Choise B",g2) alpar@85: .refOption("grc","Choise C",g3) alpar@85: .optionGroup("gr","gra") alpar@85: .optionGroup("gr","grb") alpar@85: .optionGroup("gr","grc") alpar@85: .mandatoryGroup("gr") alpar@85: .onlyOneGroup("gr") alpar@85: .other("infile","The input file") alpar@85: .other("..."); alpar@85: alpar@85: ap.parse(); alpar@85: alpar@85: std::cout << "Parameters of '" << ap.commandName() << "':\n"; alpar@85: alpar@85: if(ap.given("n")) std::cout << " Value of -n: " << i << std::endl; alpar@85: if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl; alpar@85: if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl; alpar@85: if(ap.given("f")) std::cout << " -f is given\n"; alpar@85: if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << sil << std::endl; alpar@85: alpar@85: switch(ap.files().size()) { alpar@85: case 0: alpar@85: std::cout << " No file argument was given.\n"; alpar@85: break; alpar@85: case 1: alpar@85: std::cout << " 1 file argument was given. It is:\n"; alpar@85: break; alpar@85: default: alpar@85: std::cout << " " alpar@85: << ap.files().size() << " file arguments were given. They are:\n"; alpar@85: } alpar@85: for(unsigned int i=0;i