41#ifndef _DWMOPTARGS_HH_
42#define _DWMOPTARGS_HH_
57 template <
typename T>
class Argument;
87 Argument & operator = (
const std::string & s)
89 StringUtils::StringTo(s, _value);
104 friend std::ostream &
105 operator << <> (std::ostream & os,
const Argument<T> & arg);
125 OptArg(
const std::string & c,
const std::string & longName =
"",
126 bool isRequired =
false,
const std::string & value =
"",
127 const std::string & help =
"");
132 const std::string &
Name()
const;
162 const std::string &
Value(
const std::string & value);
167 const std::string &
Help()
const;
172 const std::string &
Help(
const std::string & help);
176 std::string _longName;
202 void AddOptArg(
const std::string & name,
const std::string & longName,
203 bool isRequired =
false,
const std::string & def =
"",
204 const std::string & help =
"");
206 void AddNormalArg(
const std::string & name,
bool required);
211 template <
typename T>
215 std::map<int,OptArg>::const_iterator i = _args.find(c);
216 if (i != _args.end()) {
217 rc = i->second.Value();
225 template <
typename T>
226 T
Get(
const std::string & s)
229 std::map<std::string,OptArg *>::const_iterator i = _longArgs.find(s);
230 if (i != _longArgs.end()) {
231 rc = i->second->Value();
241 int Parse(
int argc,
const std::string argv[]);
253 void Usage(
const std::string & argv0)
const;
256 std::map<int,OptArg> _args;
257 std::map<std::string,OptArg *> _longArgs;
259 std::vector<std::pair<std::string,bool> > _normalArgs;
std::ostream & operator<<(std::ostream &os, const Dwm::ProcessInfo &pi)
ostream output operator
Miscellaneous string utilities.
Encapsulate a single argument.
Definition DwmOptArgs.hh:75
Encapsulates a command line option and its argument (if it takes an argument).
Definition DwmOptArgs.hh:118
const std::string & Value(const std::string &value)
Sets and returns the value of the argument.
const std::string & Help(const std::string &help)
Sets and returns the help text for the argument.
bool IsRequired(bool isRequired)
Sets whether or not the option is required.
bool NeedsArg() const
Returns true if an argument is required for the option.
const std::string & Name() const
Returns the name of the option.
const std::string & LongName() const
Returns the long name for the option.
const std::string & Value() const
Returns the value of the argument.
bool IsRequired() const
Returns whether or not the option is required.
const std::string & Help() const
Returns the help text for the argument.
Class to encapsulate command line options and parse them.
Definition DwmOptArgs.hh:187
T Get(int c)
Fetches the value of an optional argument by its short name.
Definition DwmOptArgs.hh:212
int Parse(int argc, const std::string argv[])
Parses all optional arguments.
void AddOptArg(const OptArg &optarg)
Adds an optional argument.
int Parse(int argc, char *argv[])
Parses all optional arguments.
void AddOptArg(const std::string &name, const std::string &longName, bool isRequired=false, const std::string &def="", const std::string &help="")
Adds an optional argument.
void Usage(const std::string &argv0) const
Prints the usage statement.
T Get(const std::string &s)
Fetches the value of an optional argument by its long name.
Definition DwmOptArgs.hh:226