equal
deleted
inserted
replaced
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
1 /* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 * |
2 * |
3 * This file is a part of LEMON, a generic C++ optimization library. |
3 * This file is a part of LEMON, a generic C++ optimization library. |
4 * |
4 * |
5 * Copyright (C) 2003-2009 |
5 * Copyright (C) 2003-2010 |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
7 * (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 * |
8 * |
9 * Permission to use, modify and distribute this software is granted |
9 * Permission to use, modify and distribute this software is granted |
10 * provided that this copyright notice appears in all copies. For |
10 * provided that this copyright notice appears in all copies. For |
40 enum Reason { |
40 enum Reason { |
41 HELP, /// <tt>--help</tt> option was given |
41 HELP, /// <tt>--help</tt> option was given |
42 UNKNOWN_OPT, /// Unknown option was given |
42 UNKNOWN_OPT, /// Unknown option was given |
43 INVALID_OPT /// Invalid combination of options |
43 INVALID_OPT /// Invalid combination of options |
44 }; |
44 }; |
45 |
45 |
46 private: |
46 private: |
47 Reason _reason; |
47 Reason _reason; |
48 |
48 |
49 public: |
49 public: |
50 ///Constructor |
50 ///Constructor |
51 ArgParserException(Reason r) throw() : _reason(r) {} |
51 ArgParserException(Reason r) throw() : _reason(r) {} |
52 ///Virtual destructor |
52 ///Virtual destructor |
53 virtual ~ArgParserException() throw() {} |
53 virtual ~ArgParserException() throw() {} |
139 |
139 |
140 std::vector<OtherArg> _others_help; |
140 std::vector<OtherArg> _others_help; |
141 std::vector<std::string> _file_args; |
141 std::vector<std::string> _file_args; |
142 std::string _command_name; |
142 std::string _command_name; |
143 |
143 |
144 |
144 |
145 private: |
145 private: |
146 //Bind a function to an option. |
146 //Bind a function to an option. |
147 |
147 |
148 //\param name The name of the option. The leading '-' must be omitted. |
148 //\param name The name of the option. The leading '-' must be omitted. |
149 //\param help A help string. |
149 //\param help A help string. |
153 ArgParser &funcOption(const std::string &name, |
153 ArgParser &funcOption(const std::string &name, |
154 const std::string &help, |
154 const std::string &help, |
155 void (*func)(void *),void *data); |
155 void (*func)(void *),void *data); |
156 |
156 |
157 bool _exit_on_problems; |
157 bool _exit_on_problems; |
158 |
158 |
159 void _terminate(ArgParserException::Reason reason) const; |
159 void _terminate(ArgParserException::Reason reason) const; |
160 |
160 |
161 public: |
161 public: |
162 |
162 |
163 ///Constructor |
163 ///Constructor |
421 ///Give back a reference to a vector consisting of the program arguments |
421 ///Give back a reference to a vector consisting of the program arguments |
422 ///not starting with a '-' character. |
422 ///not starting with a '-' character. |
423 const std::vector<std::string> &files() const { return _file_args; } |
423 const std::vector<std::string> &files() const { return _file_args; } |
424 |
424 |
425 ///Throw instead of exit in case of problems |
425 ///Throw instead of exit in case of problems |
426 void throwOnProblems() |
426 void throwOnProblems() |
427 { |
427 { |
428 _exit_on_problems=false; |
428 _exit_on_problems=false; |
429 } |
429 } |
430 }; |
430 }; |
431 } |
431 } |