965 |
11 Oct 07 |
peter |
1 |
#ifndef _theplu_yat_utility_option_switch_ |
965 |
11 Oct 07 |
peter |
2 |
#define _theplu_yat_utility_option_switch_ |
965 |
11 Oct 07 |
peter |
3 |
|
965 |
11 Oct 07 |
peter |
// $Id$ |
965 |
11 Oct 07 |
peter |
5 |
|
965 |
11 Oct 07 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
965 |
11 Oct 07 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
965 |
11 Oct 07 |
peter |
11 |
|
965 |
11 Oct 07 |
peter |
The yat library is free software; you can redistribute it and/or |
965 |
11 Oct 07 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
965 |
11 Oct 07 |
peter |
License, or (at your option) any later version. |
965 |
11 Oct 07 |
peter |
16 |
|
965 |
11 Oct 07 |
peter |
The yat library is distributed in the hope that it will be useful, |
965 |
11 Oct 07 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
965 |
11 Oct 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
965 |
11 Oct 07 |
peter |
General Public License for more details. |
965 |
11 Oct 07 |
peter |
21 |
|
965 |
11 Oct 07 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
965 |
11 Oct 07 |
peter |
24 |
*/ |
965 |
11 Oct 07 |
peter |
25 |
|
965 |
11 Oct 07 |
peter |
26 |
#include "Option.h" |
965 |
11 Oct 07 |
peter |
27 |
|
965 |
11 Oct 07 |
peter |
28 |
#include <string> |
965 |
11 Oct 07 |
peter |
29 |
|
965 |
11 Oct 07 |
peter |
30 |
namespace theplu { |
965 |
11 Oct 07 |
peter |
31 |
namespace yat { |
965 |
11 Oct 07 |
peter |
32 |
namespace utility { |
965 |
11 Oct 07 |
peter |
33 |
|
965 |
11 Oct 07 |
peter |
34 |
class CommandLine; |
965 |
11 Oct 07 |
peter |
35 |
/** |
965 |
11 Oct 07 |
peter |
\brief Class for switch option |
965 |
11 Oct 07 |
peter |
37 |
*/ |
965 |
11 Oct 07 |
peter |
38 |
class OptionSwitch : public Option |
965 |
11 Oct 07 |
peter |
39 |
{ |
965 |
11 Oct 07 |
peter |
40 |
public: |
965 |
11 Oct 07 |
peter |
41 |
/** |
4200 |
19 Aug 22 |
peter |
\brief Constructor |
4200 |
19 Aug 22 |
peter |
43 |
|
965 |
11 Oct 07 |
peter |
\param cmd Commandline Option is associated with |
965 |
11 Oct 07 |
peter |
\param name string such as "help" for --help, "h" for -h or |
965 |
11 Oct 07 |
peter |
"h,help" for having both short and long option name |
965 |
11 Oct 07 |
peter |
\param desc string used in help display |
965 |
11 Oct 07 |
peter |
\param def default value for switch |
965 |
11 Oct 07 |
peter |
49 |
*/ |
4200 |
19 Aug 22 |
peter |
50 |
OptionSwitch(CommandLine& cmd, std::string name, |
4200 |
19 Aug 22 |
peter |
51 |
std::string desc, bool def=false); |
965 |
11 Oct 07 |
peter |
52 |
|
965 |
11 Oct 07 |
peter |
53 |
|
965 |
11 Oct 07 |
peter |
54 |
/** |
965 |
11 Oct 07 |
peter |
\brief return value |
965 |
11 Oct 07 |
peter |
56 |
*/ |
965 |
11 Oct 07 |
peter |
57 |
bool value(void) const; |
965 |
11 Oct 07 |
peter |
58 |
|
965 |
11 Oct 07 |
peter |
59 |
private: |
965 |
11 Oct 07 |
peter |
60 |
/** |
965 |
11 Oct 07 |
peter |
61 |
*/ |
4200 |
19 Aug 22 |
peter |
62 |
void do_parse(std::vector<std::string>::iterator&, |
1465 |
02 Sep 08 |
peter |
63 |
const std::vector<std::string>::iterator&); |
965 |
11 Oct 07 |
peter |
64 |
|
965 |
11 Oct 07 |
peter |
65 |
/** |
981 |
22 Oct 07 |
peter |
called inside do_parse and allows inherited classes to add |
981 |
22 Oct 07 |
peter |
stuff to do_parse. |
965 |
11 Oct 07 |
peter |
68 |
*/ |
4200 |
19 Aug 22 |
peter |
69 |
virtual void do_parse2(std::vector<std::string>::iterator, |
981 |
22 Oct 07 |
peter |
70 |
std::vector<std::string>::iterator); |
981 |
22 Oct 07 |
peter |
71 |
|
981 |
22 Oct 07 |
peter |
72 |
/** |
981 |
22 Oct 07 |
peter |
73 |
*/ |
965 |
11 Oct 07 |
peter |
74 |
std::string print2(void) const; |
965 |
11 Oct 07 |
peter |
75 |
|
965 |
11 Oct 07 |
peter |
76 |
/** |
965 |
11 Oct 07 |
peter |
77 |
*/ |
965 |
11 Oct 07 |
peter |
78 |
void do_validate(void) const; |
965 |
11 Oct 07 |
peter |
79 |
|
965 |
11 Oct 07 |
peter |
80 |
private: |
965 |
11 Oct 07 |
peter |
81 |
bool def_; |
965 |
11 Oct 07 |
peter |
82 |
bool switch_; |
965 |
11 Oct 07 |
peter |
83 |
}; |
965 |
11 Oct 07 |
peter |
84 |
|
965 |
11 Oct 07 |
peter |
85 |
}}} // of namespace utility, yat, and theplu |
965 |
11 Oct 07 |
peter |
86 |
|
965 |
11 Oct 07 |
peter |
87 |
#endif |