delete *i;
}
+GetOpt::OptBase &GetOpt::add_option(OptBase *opt)
+{
+ for(list<OptBase *>::iterator i=opts.begin(); i!=opts.end(); )
+ {
+ if((opt->get_short()!=0 && (*i)->get_short()==opt->get_short()) || (*i)->get_long()==opt->get_long())
+ {
+ delete *i;
+ opts.erase(i++);
+ }
+ else
+ ++i;
+ }
+
+ opts.push_back(opt);
+ return *opts.back();
+}
+
GetOpt::OptBase &GetOpt::get_option(char s)
{
for(list<OptBase *>::iterator i=opts.begin(); i!=opts.end(); ++i)
lng(l),
arg_type(a),
seen_count(0),
+ ext_seen_count(0),
metavar("ARG")
{
if(lng.empty())
return *this;
}
+GetOpt::OptBase &GetOpt::OptBase::bind_seen_count(unsigned &c)
+{
+ ext_seen_count = &c;
+ return *this;
+}
+
void GetOpt::OptBase::process()
{
if(arg_type==REQUIRED_ARG)
throw usage_error("--"+lng+" requires an argument");
++seen_count;
+ if(ext_seen_count)
+ *ext_seen_count = seen_count;
store();
}
if(arg_type==NO_ARG)
throw usage_error("--"+lng+" takes no argument");
++seen_count;
+ if(ext_seen_count)
+ *ext_seen_count = seen_count;
store(arg);
}