+ if(l.empty())
+ throw invalid_argument("GetOpt::add_option");
+ if(t.is_list() && a!=REQUIRED_ARG)
+ throw invalid_argument("GetOpt::add_option");
+
+ for(auto i=opts.begin(); i!=opts.end(); )
+ {
+ if((s!=0 && (*i)->get_short()==s) || (*i)->get_long()==l)
+ {
+ delete *i;
+ opts.erase(i++);
+ }
+ else
+ ++i;
+ }
+
+ opts.push_back(new OptionImpl(s, l, t, a));
+ return *opts.back();
+}
+
+GetOpt::ArgumentImpl &GetOpt::add_argument(const string &n, const Store &t, ArgType y)
+{
+ if(y==NO_ARG)
+ throw invalid_argument("GetOpt::add_argument");
+
+ bool have_list = false;
+ bool have_optional = false;
+ for(const ArgumentImpl *a: args)
+ {
+ if(a->is_list_store())
+ have_list = true;
+ else if(a->get_type()==OPTIONAL_ARG)
+ have_optional = true;
+ }
+
+ if(have_optional && (t.is_list() || y!=OPTIONAL_ARG))
+ throw invalid_argument("GetOpt::add_argument");
+ if(have_list && (t.is_list() || y==OPTIONAL_ARG))
+ throw invalid_argument("GetOpt::add_argument");
+
+ args.push_back(new ArgumentImpl(n, t, y));
+ return *args.back();
+}
+
+GetOpt::OptionImpl &GetOpt::get_option(char s)
+{
+ auto i = find_if(opts, [s](const OptionImpl *o){ return o->get_short()==s; });
+ if(i!=opts.end())
+ return **i;