1 | // $Id: OptionSwitch.cc 1487 2008-09-10 08:41:36Z jari $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 3 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include "OptionSwitch.h" |
---|
23 | |
---|
24 | #include <sstream> |
---|
25 | #include <string> |
---|
26 | |
---|
27 | namespace theplu { |
---|
28 | namespace yat { |
---|
29 | namespace utility { |
---|
30 | |
---|
31 | |
---|
32 | OptionSwitch::OptionSwitch(CommandLine& cmd, std::string flag, |
---|
33 | std::string desc, bool def) |
---|
34 | : Option(cmd, flag, desc), def_(def), switch_(def) |
---|
35 | { |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | void OptionSwitch::do_parse(std::vector<std::string>::iterator& first, |
---|
40 | const std::vector<std::string>::iterator& last) |
---|
41 | { |
---|
42 | if (long_name().size()>3 && long_name().substr(0,3)=="no-") |
---|
43 | switch_=false; |
---|
44 | else |
---|
45 | switch_=true; |
---|
46 | do_parse2(first, last); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | void OptionSwitch::do_parse2(std::vector<std::string>::iterator first, |
---|
51 | std::vector<std::string>::iterator last) |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | std::string OptionSwitch::print2(void) const |
---|
57 | { |
---|
58 | std::string str; |
---|
59 | if (long_name().size()){ |
---|
60 | str = " --"; |
---|
61 | if (def_ && long_name().size()>3 && long_name().substr(0,3)!="no-") |
---|
62 | str += "no-"; |
---|
63 | str += long_name(); |
---|
64 | } |
---|
65 | return str; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | void OptionSwitch::do_validate() const |
---|
70 | { |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | bool OptionSwitch::value(void) const |
---|
75 | { |
---|
76 | return switch_; |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | }}} // of namespace utility, yat, and theplu |
---|