29 typedef std::vector<std::string> OptionValues;
30 typedef std::map<std::string, OptionValues> OptionsMap;
37 Getopt (
int argc,
char *
const *
argv,
const char *documentation =
"Usage: %c [options]");
47 void add (
const char *longOpt,
char shortOpt,
int argument,
48 const char *description =
"",
const char *argDescription =
"");
60 inline std::string
usage ();
67 inline std::string
operator[] (std::string opt)
const;
72 inline int getCount (std::string opt)
const;
77 inline const OptionValues &
getAll (std::string opt)
const;
83 inline std::string
shift ();
87 inline int argc ()
const;
91 inline char const *
const *
argv ()
const;
95 inline std::string
argv (
int i)
const;
98 void addOpt (
const char *longOpt,
char shortOpt,
int argument,
99 const char *description,
const char *argDescription);
100 void addUsage (
const char *longOpt,
char shortOpt,
int argument,
101 const char *description,
const char *argDescription);
105 typedef struct option Option;
108 std::string shortOpts_;
109 std::ostringstream usage_;
110 std::vector<Option> options_;
111 std::map<char,int> shortIndex_;
113 static const OptionValues None_;
123 OptionsMap::const_iterator it = cl_.find(opt);
124 if (it == cl_.end()) {
128 return it->second.back();
133 OptionsMap::const_iterator it = cl_.find(opt);
134 if (it == cl_.end()) {
138 return it->second.size();
143 OptionsMap::const_iterator it = cl_.find(opt);
144 if (it == cl_.end()) {
153 if (optind == argc_) {
157 std::string res = argv_[optind];
174 return argv_[optind+i];
178 bool fromString(T& t,
const std::string& s)
180 std::istringstream iss(s);
181 return !(iss >> t).fail();