]>
Commit | Line | Data |
---|---|---|
1ae8e28d RC |
1 | /* |
2 | * Copyright (c) 2002 Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <robertc@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | #include <getopt++/StringOption.h> | |
17 | ||
155eacb6 | 18 | StringOption::StringOption(std::string const defaultvalue, char shortopt, |
20f237b4 | 19 | char const *longopt, unsigned int shorthelp, |
155eacb6 | 20 | bool const optional, OptionSet &owner) : |
1ae8e28d RC |
21 | _value (defaultvalue) , _shortopt(shortopt), |
22 | _longopt (longopt), _shorthelp (shorthelp) | |
23 | { | |
24 | if (!optional) | |
1d644c06 | 25 | _optional = Required; |
1ae8e28d | 26 | else |
1d644c06 | 27 | _optional = Optional; |
1ae8e28d RC |
28 | owner.Register (this); |
29 | }; | |
30 | ||
31 | StringOption::~ StringOption () {}; | |
32 | ||
155eacb6 | 33 | std::string const |
1ae8e28d RC |
34 | StringOption::shortOption () const |
35 | { | |
155eacb6 | 36 | return std::string() + _shortopt + ":"; |
1ae8e28d RC |
37 | } |
38 | ||
155eacb6 | 39 | std::string const |
1ae8e28d RC |
40 | StringOption::longOption () const |
41 | { | |
1d644c06 | 42 | return _longopt; |
1ae8e28d RC |
43 | } |
44 | ||
20f237b4 | 45 | unsigned int |
1ae8e28d RC |
46 | StringOption::shortHelp () const |
47 | { | |
48 | return _shorthelp; | |
49 | } | |
50 | ||
155eacb6 | 51 | Option::Result |
8effde7a | 52 | StringOption::Process (char const *optarg, int prefixIndex) |
1ae8e28d RC |
53 | { |
54 | if (optarg) | |
55 | _value = optarg; | |
1d644c06 RC |
56 | if (optarg || _optional == Optional) |
57 | return Ok; | |
58 | return Failed; | |
1ae8e28d RC |
59 | } |
60 | ||
155eacb6 | 61 | StringOption::operator const std::string& () const |
1ae8e28d RC |
62 | { |
63 | return _value; | |
64 | } | |
1d644c06 RC |
65 | |
66 | Option::Argument | |
67 | StringOption::argument () const | |
68 | { | |
69 | return _optional; | |
70 | } |