]> cygwin.com Git - cygwin-apps/setup.git/blame - libgetopt++/src/StringOption.cc
Implement paired boolean options
[cygwin-apps/setup.git] / libgetopt++ / src / StringOption.cc
CommitLineData
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
AG
18StringOption::StringOption(std::string const defaultvalue, char shortopt,
19 char const *longopt, std::string const &shorthelp,
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
31StringOption::~ StringOption () {};
32
155eacb6 33std::string const
1ae8e28d
RC
34StringOption::shortOption () const
35{
155eacb6 36 return std::string() + _shortopt + ":";
1ae8e28d
RC
37}
38
155eacb6 39std::string const
1ae8e28d
RC
40StringOption::longOption () const
41{
1d644c06 42 return _longopt;
1ae8e28d
RC
43}
44
155eacb6 45std::string const
1ae8e28d
RC
46StringOption::shortHelp () const
47{
48 return _shorthelp;
49}
50
155eacb6 51Option::Result
8effde7a 52StringOption::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 61StringOption::operator const std::string& () const
1ae8e28d
RC
62{
63 return _value;
64}
1d644c06
RC
65
66Option::Argument
67StringOption::argument () const
68{
69 return _optional;
70}
This page took 0.11235 seconds and 5 git commands to generate.