965 |
11 Oct 07 |
peter |
// $Id$ |
965 |
11 Oct 07 |
peter |
2 |
|
965 |
11 Oct 07 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
965 |
11 Oct 07 |
peter |
7 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
965 |
11 Oct 07 |
peter |
9 |
|
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 |
14 |
|
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 |
19 |
|
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 |
22 |
*/ |
965 |
11 Oct 07 |
peter |
23 |
|
2881 |
18 Nov 12 |
peter |
24 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
25 |
|
965 |
11 Oct 07 |
peter |
26 |
#include "OptionSwitch.h" |
965 |
11 Oct 07 |
peter |
27 |
|
965 |
11 Oct 07 |
peter |
28 |
#include <sstream> |
965 |
11 Oct 07 |
peter |
29 |
#include <string> |
965 |
11 Oct 07 |
peter |
30 |
|
965 |
11 Oct 07 |
peter |
31 |
namespace theplu { |
965 |
11 Oct 07 |
peter |
32 |
namespace yat { |
965 |
11 Oct 07 |
peter |
33 |
namespace utility { |
965 |
11 Oct 07 |
peter |
34 |
|
965 |
11 Oct 07 |
peter |
35 |
|
4200 |
19 Aug 22 |
peter |
36 |
OptionSwitch::OptionSwitch(CommandLine& cmd, std::string flag, |
965 |
11 Oct 07 |
peter |
37 |
std::string desc, bool def) |
965 |
11 Oct 07 |
peter |
38 |
: Option(cmd, flag, desc), def_(def), switch_(def) |
965 |
11 Oct 07 |
peter |
39 |
{ |
965 |
11 Oct 07 |
peter |
40 |
} |
965 |
11 Oct 07 |
peter |
41 |
|
965 |
11 Oct 07 |
peter |
42 |
|
4200 |
19 Aug 22 |
peter |
43 |
void OptionSwitch::do_parse(std::vector<std::string>::iterator& first, |
1465 |
02 Sep 08 |
peter |
44 |
const std::vector<std::string>::iterator& last) |
4200 |
19 Aug 22 |
peter |
45 |
{ |
1634 |
19 Nov 08 |
peter |
46 |
if (first->size()>3 && first->substr(0,3)=="no-") |
996 |
03 Dec 07 |
peter |
47 |
switch_=false; |
996 |
03 Dec 07 |
peter |
48 |
else |
996 |
03 Dec 07 |
peter |
49 |
switch_=true; |
981 |
22 Oct 07 |
peter |
50 |
do_parse2(first, last); |
965 |
11 Oct 07 |
peter |
51 |
} |
965 |
11 Oct 07 |
peter |
52 |
|
965 |
11 Oct 07 |
peter |
53 |
|
4200 |
19 Aug 22 |
peter |
54 |
void OptionSwitch::do_parse2(std::vector<std::string>::iterator first, |
981 |
22 Oct 07 |
peter |
55 |
std::vector<std::string>::iterator last) |
4200 |
19 Aug 22 |
peter |
56 |
{ |
981 |
22 Oct 07 |
peter |
57 |
} |
981 |
22 Oct 07 |
peter |
58 |
|
981 |
22 Oct 07 |
peter |
59 |
|
965 |
11 Oct 07 |
peter |
60 |
std::string OptionSwitch::print2(void) const |
965 |
11 Oct 07 |
peter |
61 |
{ |
965 |
11 Oct 07 |
peter |
62 |
std::string str; |
4200 |
19 Aug 22 |
peter |
63 |
if (long_name().size()){ |
965 |
11 Oct 07 |
peter |
64 |
str = " --"; |
996 |
03 Dec 07 |
peter |
65 |
if (def_ && long_name().size()>3 && long_name().substr(0,3)!="no-") |
965 |
11 Oct 07 |
peter |
66 |
str += "no-"; |
965 |
11 Oct 07 |
peter |
67 |
str += long_name(); |
965 |
11 Oct 07 |
peter |
68 |
} |
965 |
11 Oct 07 |
peter |
69 |
return str; |
965 |
11 Oct 07 |
peter |
70 |
} |
965 |
11 Oct 07 |
peter |
71 |
|
965 |
11 Oct 07 |
peter |
72 |
|
965 |
11 Oct 07 |
peter |
73 |
void OptionSwitch::do_validate() const |
4200 |
19 Aug 22 |
peter |
74 |
{ |
965 |
11 Oct 07 |
peter |
75 |
} |
965 |
11 Oct 07 |
peter |
76 |
|
965 |
11 Oct 07 |
peter |
77 |
|
965 |
11 Oct 07 |
peter |
78 |
bool OptionSwitch::value(void) const |
4200 |
19 Aug 22 |
peter |
79 |
{ |
4200 |
19 Aug 22 |
peter |
80 |
return switch_; |
965 |
11 Oct 07 |
peter |
81 |
} |
965 |
11 Oct 07 |
peter |
82 |
|
965 |
11 Oct 07 |
peter |
83 |
|
965 |
11 Oct 07 |
peter |
84 |
}}} // of namespace utility, yat, and theplu |