Ignore:
Timestamp:
Aug 21, 2008, 12:26:31 AM (15 years ago)
Author:
Peter
Message:

fixes #414

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/CommandLine.cc

    r1275 r1426  
    5656  void CommandLine::add(Option& option)
    5757  {
    58     if (option.long_name().size())
     58    if (option.long_name().size()) {
     59      if (long_options_.find(option.long_name())!=long_options_.end()) {
     60        std::stringstream ss;
     61        ss << "yat::utility::Commandline: two options with long_name: "
     62           << option.long_name();
     63        throw std::runtime_error(ss.str());
     64      }
    5965      long_options_[option.long_name()] = &option;
    60     if (option.short_name())
     66    }
     67    if (option.short_name()) {
     68      if (short_options_.find(option.short_name())!=short_options_.end()) {
     69        std::stringstream ss;
     70        ss << "yat::utility::Commandline: two options with short_name: "
     71           << option.short_name();
     72        throw std::runtime_error(ss.str());
     73      }
    6174      short_options_[option.short_name()] = &option;
     75    }
    6276    if (option.long_name().size() || option.short_name())
    6377      options_.push_back(&option);
    6478    // allow `no-switch' for option `switch'
    6579    OptionSwitch* o = dynamic_cast<OptionSwitch*>(&option);
     80    std::string no_name = std::string("no-")+option.long_name();
    6681    if (option.long_name().size() && o &&
    67         !( o->long_name().size()>2 && o->long_name().substr(0,3)=="no-"))
    68       long_options_[std::string("no-")+option.long_name()] = &option;
     82        !( o->long_name().size()>2 && o->long_name().substr(0,3)=="no-") &&
     83        long_options_.find(no_name)==long_options_.end())
     84      long_options_[no_name] = &option;
    6985  }
    7086
Note: See TracChangeset for help on using the changeset viewer.