delete *i;
}
+GetOpt::OptBase &GetOpt::add_option(OptBase *opt)
+{
+ for(list<OptBase *>::iterator i=opts.begin(); i!=opts.end(); )
+ {
+ if((*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)
template<typename T>
OptBase &add_option(char s, const std::string &l, T &d, ArgType a = NO_ARG)
- { opts.push_back(new Option<T>(s, l, d, a)); return *opts.back(); }
+ { return add_option(new Option<T>(s, l, d, a)); }
template<typename T>
OptBase &add_option(char s, const std::string &l, std::list<T> &d, ArgType a = REQUIRED_ARG)
- { opts.push_back(new ListOption<std::list<T> >(s, l, d, a)); return *opts.back(); }
+ { return add_option(new ListOption<std::list<T> >(s, l, d, a)); }
template<typename T>
OptBase &add_option(const std::string &l, T &d, ArgType a)
{ return add_option(0, l, d, a); }
private:
+ OptBase &add_option(OptBase *);
+
OptBase &get_option(char);
OptBase &get_option(const std::string &);