COIN-OR::LEMON - Graph Library

Changeset 2410:fe46b61da4e3 in lemon-0.x for lemon


Ignore:
Timestamp:
03/14/07 19:01:04 (17 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3241
Message:

dim_to_lgf

  • use the argparser class

arg_parser improvments

  • usage of assert in cc
  • const char argv

error

  • handling the string parameter
Location:
lemon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/arg_parser.cc

    r2406 r2410  
    2727  }
    2828
    29   ArgParser::ArgParser(int argc, char **argv) :_argc(argc), _argv(argv),
    30                                                _command_name(argv[0]) {
     29  ArgParser::ArgParser(int argc, const char **argv) :_argc(argc), _argv(argv),
     30                                                     _command_name(argv[0]) {
    3131    funcOption("-help","Print a short help message",_showHelp,this);
    3232    synonym("help","-help");
     
    135135
    136136  ArgParser &ArgParser::refOption(const std::string &name,
    137                                const std::string &help,
    138                                double &ref, bool obl)
     137                                  const std::string &help,
     138                                  double &ref, bool obl)
    139139  {
    140140    ParData p;
     
    149149
    150150  ArgParser &ArgParser::refOption(const std::string &name,
    151                                const std::string &help,
    152                                bool &ref, bool obl)
     151                                  const std::string &help,
     152                                  bool &ref, bool obl)
    153153  {
    154154    ParData p;
     
    198198  {
    199199    Opts::iterator i = _opts.find(opt);
    200     if(i==_opts.end()) throw LogicError();
    201     else if(i->second.ingroup) throw LogicError();
    202     else {
    203       GroupData &g=_groups[group];
    204       g.opts.push_back(opt);
    205       i->second.ingroup=true;
    206     }
     200    LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'");
     201    LEMON_ASSERT(!(i->second.ingroup),
     202                 "Option already in option group: '"+opt+"'");
     203    GroupData &g=_groups[group];
     204    g.opts.push_back(opt);
     205    i->second.ingroup=true;
    207206    return *this;
    208207  }
     
    220219    Opts::iterator o = _opts.find(opt);
    221220    Opts::iterator s = _opts.find(syn);
    222     if(o==_opts.end()||s!=_opts.end())
    223       throw LogicError();
    224     else {
    225       ParData p;
    226       p.help=opt;
    227       p.mandatory=false;
    228       p.syn=true;
    229       _opts[syn]=p;
    230       o->second.has_syn=true;
    231     }
     221    LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'");
     222    LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'");
     223    ParData p;
     224    p.help=opt;
     225    p.mandatory=false;
     226    p.syn=true;
     227    _opts[syn]=p;
     228    o->second.has_syn=true;
    232229    return *this;
    233230  }
  • lemon/arg_parser.h

    r2407 r2410  
    4848   
    4949    int _argc;
    50     char **_argv;
     50    const char **_argv;
    5151   
    5252    enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 };
     
    108108
    109109    ///\e
    110     ArgParser(int argc, char **argv);
     110    ArgParser(int argc, const char **argv);
    111111
    112112    ~ArgParser();
  • lemon/error.h

    r2391 r2410  
    476476
    477477  template <typename Exception>
    478   inline void assert_fail(const char *file, int line, const char *func,
    479                    Exception exception, const char *assertion = 0,
    480                    bool do_abort=true)
     478  inline void assert_fail(const char *file, int line,
     479                          const char *func,
     480                          Exception exception,
     481                          const char *assertion = 0,
     482                          bool do_abort=true)
    481483  {
    482484    using namespace std;
     
    511513  }
    512514
     515  template <>
     516  inline void assert_fail<std::string>(const char *file, int line,
     517                                       const char *func,
     518                                       std::string message,
     519                                       const char *assertion,
     520                                       bool do_abort)
     521  {
     522    assert_fail(file, line, func, message.c_str(), assertion, do_abort);
     523  }
     524
    513525  template <typename Exception>
    514526  inline void assert_fail_failure(const char *file, int line, const char *func,
     
    522534  template <>
    523535  inline void assert_fail_failure<const char *>(const char *file, int line,
    524                                         const char *func,
    525                                         const char *message,
    526                                         const char *assertion,
    527                                         bool)
     536                                                const char *func,
     537                                                const char *message,
     538                                                const char *assertion,
     539                                                bool)
    528540  {
    529541    throw AssertionFailedError(file, line, func, message, assertion);
     542  }
     543
     544  template <>
     545  inline void assert_fail_failure<std::string>(const char *file, int line,
     546                                               const char *func,
     547                                               std::string message,
     548                                               const char *assertion,
     549                                               bool)
     550  {
     551    assert_fail_failure(file, line, func, message.c_str(), assertion, true);
    530552  }
    531553
     
    546568  {
    547569    throw AssertionFailedError(file, line, func, message, assertion);
     570  }
     571
     572  template <>
     573  inline void assert_fail_exception<std::string>(const char *file, int line,
     574                                                 const char *func,
     575                                                 std::string message,
     576                                                 const char *assertion,
     577                                                 bool)
     578  {
     579    assert_fail_exception(file, line, func, message.c_str(), assertion, true);   
    548580  }
    549581
Note: See TracChangeset for help on using the changeset viewer.