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: /// kpeter@88: /// This example shows how the argument parser can be used. alpar@85: /// kpeter@88: /// \include arg_parser_demo.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; kpeter@88: ap.refOption("n", "An integer input.", i, true) kpeter@88: .refOption("val", "A double input.", d) alpar@128: .doubleOption("val2", "A double input.", d) alpar@85: .synonym("vals","val") kpeter@88: .refOption("name", "A string input.", s) kpeter@88: .refOption("f", "A switch.", b) alpar@85: .refOption("nohelp", "", sil) kpeter@88: .refOption("gra","Choice A",g1) kpeter@88: .refOption("grb","Choice B",g2) kpeter@88: .refOption("grc","Choice C",g3) alpar@85: .optionGroup("gr","gra") alpar@137: .optionGroup("gr","grb") alpar@85: .optionGroup("gr","grc") alpar@85: .mandatoryGroup("gr") alpar@85: .onlyOneGroup("gr") kpeter@88: .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; kpeter@88: if(ap.given("gra")) std::cout << " -gra is given\n"; kpeter@88: if(ap.given("grb")) std::cout << " -grb is given\n"; kpeter@88: if(ap.given("grc")) std::cout << " -grc is given\n"; kpeter@88: 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