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