]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/getopt.cpp
Check that the option actually has a short name
[libs/core.git] / source / core / getopt.cpp
index cfc9d7a02fa99e547cc19afefecf6c32250691b3..766b858e8d4aa4b2212b94f51756cad0a07a964b 100644 (file)
@@ -17,6 +17,23 @@ GetOpt::~GetOpt()
                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)