lemon/arg_parser.cc
changeset 2410 fe46b61da4e3
parent 2406 0ffc78641b34
child 2553 bfced05fa852
     1.1 --- a/lemon/arg_parser.cc	Tue Mar 13 16:32:35 2007 +0000
     1.2 +++ b/lemon/arg_parser.cc	Wed Mar 14 18:01:04 2007 +0000
     1.3 @@ -26,8 +26,8 @@
     1.4      exit(1);
     1.5    }
     1.6  
     1.7 -  ArgParser::ArgParser(int argc, char **argv) :_argc(argc), _argv(argv),
     1.8 -					       _command_name(argv[0]) {
     1.9 +  ArgParser::ArgParser(int argc, const char **argv) :_argc(argc), _argv(argv),
    1.10 +                                                     _command_name(argv[0]) {
    1.11      funcOption("-help","Print a short help message",_showHelp,this);
    1.12      synonym("help","-help");
    1.13      synonym("h","-help");
    1.14 @@ -134,8 +134,8 @@
    1.15    }
    1.16  
    1.17    ArgParser &ArgParser::refOption(const std::string &name,
    1.18 -			       const std::string &help,
    1.19 -			       double &ref, bool obl)
    1.20 +                                  const std::string &help,
    1.21 +                                  double &ref, bool obl)
    1.22    {
    1.23      ParData p;
    1.24      p.double_p=&ref;
    1.25 @@ -148,8 +148,8 @@
    1.26    }
    1.27  
    1.28    ArgParser &ArgParser::refOption(const std::string &name,
    1.29 -			       const std::string &help,
    1.30 -			       bool &ref, bool obl)
    1.31 +                                  const std::string &help,
    1.32 +                                  bool &ref, bool obl)
    1.33    {
    1.34      ParData p;
    1.35      p.bool_p=&ref;
    1.36 @@ -197,13 +197,12 @@
    1.37  				    const std::string &opt)
    1.38    {
    1.39      Opts::iterator i = _opts.find(opt);
    1.40 -    if(i==_opts.end()) throw LogicError();
    1.41 -    else if(i->second.ingroup) throw LogicError();
    1.42 -    else {
    1.43 -      GroupData &g=_groups[group];
    1.44 -      g.opts.push_back(opt);
    1.45 -      i->second.ingroup=true;
    1.46 -    }
    1.47 +    LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'");
    1.48 +    LEMON_ASSERT(!(i->second.ingroup), 
    1.49 +                 "Option already in option group: '"+opt+"'");
    1.50 +    GroupData &g=_groups[group];
    1.51 +    g.opts.push_back(opt);
    1.52 +    i->second.ingroup=true;
    1.53      return *this;
    1.54    }
    1.55  
    1.56 @@ -219,16 +218,14 @@
    1.57    {
    1.58      Opts::iterator o = _opts.find(opt);
    1.59      Opts::iterator s = _opts.find(syn);
    1.60 -    if(o==_opts.end()||s!=_opts.end())
    1.61 -      throw LogicError();
    1.62 -    else {
    1.63 -      ParData p;
    1.64 -      p.help=opt;
    1.65 -      p.mandatory=false;
    1.66 -      p.syn=true;
    1.67 -      _opts[syn]=p;
    1.68 -      o->second.has_syn=true;
    1.69 -    }
    1.70 +    LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'");
    1.71 +    LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'");
    1.72 +    ParData p;
    1.73 +    p.help=opt;
    1.74 +    p.mandatory=false;
    1.75 +    p.syn=true;
    1.76 +    _opts[syn]=p;
    1.77 +    o->second.has_syn=true;
    1.78      return *this;
    1.79    }
    1.80