42 #ifndef _DWMOPTARGS_HH_ 43 #define _DWMOPTARGS_HH_ 64 std::ostream & operator << (std::ostream & os, const Argument<T> & arg)
90 StringUtils::StringTo(s, _value);
105 friend std::ostream &
106 operator << <> (std::ostream & os,
const Argument<T> & arg);
126 OptArg(
const std::string & c,
const std::string & longName =
"",
127 bool isRequired =
false,
const std::string & value =
"",
128 const std::string & help =
"");
133 const std::string & Name()
const;
138 const std::string & LongName()
const;
143 bool IsRequired()
const;
148 bool IsRequired(
bool isRequired);
153 bool NeedsArg()
const;
158 const std::string & Value()
const;
163 const std::string & Value(
const std::string & value);
168 const std::string & Help()
const;
173 const std::string & Help(
const std::string & help);
177 std::string _longName;
198 void AddOptArg(
const OptArg & optarg);
203 void AddOptArg(
const std::string & name,
const std::string & longName,
204 bool isRequired =
false,
const std::string & def =
"",
205 const std::string & help =
"");
207 void AddNormalArg(
const std::string & name,
bool required);
212 template <
typename T>
216 std::map<int,OptArg>::const_iterator i = _args.find(c);
217 if (i != _args.end()) {
218 rc = i->second.Value();
226 template <
typename T>
227 T
Get(
const std::string & s)
230 std::map<std::string,OptArg *>::const_iterator i = _longArgs.find(s);
231 if (i != _longArgs.end()) {
232 rc = i->second->Value();
242 int Parse(
int argc,
const std::string argv[]);
249 int Parse(
int argc,
char *argv[]);
254 void Usage(
const std::string & argv0)
const;
257 std::map<int,OptArg> _args;
258 std::map<std::string,OptArg *> _longArgs;
260 std::vector<std::pair<std::string,bool> > _normalArgs;
266 #endif // _DWMOPTARGS_HH_ T Get(const std::string &s)
Fetches the value of an optional argument by its long name.
Definition: DwmOptArgs.hh:227
T Get(int c)
Fetches the value of an optional argument by its short name.
Definition: DwmOptArgs.hh:213
Definition: DwmBZ2IO.hh:67
Pre-declare the Argument class template.
Definition: DwmOptArgs.hh:58
Class to encapsulate command line options and parse them.
Definition: DwmOptArgs.hh:187
Encapsulates a command line option and its argument (if it takes an argument).
Definition: DwmOptArgs.hh:118
Miscellaneous string utilities.