* Set an option's weight. * If @a weight is set to 0, the option is removed from the list of choices. * If @a id already exists, the new weight replaces the old one, otherwise * @a id is added to the list of choices, with @a weight as the weight. * @param id The option name. * @param weight The option's new weight. */
| 81 | * @param weight The option's new weight. |
| 82 | */ |
| 83 | void WeightedOptions::set(const std::string &id, size_t weight) |
| 84 | { |
| 85 | std::map<std::string, size_t>::iterator option = _choices.find(id); |
| 86 | if (option != _choices.end()) |
| 87 | { |
| 88 | _totalWeight -= option->second; |
| 89 | if (0 != weight) |
| 90 | { |
| 91 | option->second = weight; |
| 92 | _totalWeight += weight; |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | _choices.erase(option); |
| 97 | } |
| 98 | } |
| 99 | else if (0 != weight) |
| 100 | { |
| 101 | _choices.insert(std::make_pair(id, weight)); |
| 102 | _totalWeight += weight; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Add the weighted options from a YAML::Node to a WeightedOptions. |
no outgoing calls
no test coverage detected