* Select the most likely option. * This MUST be called on non-empty objects. * @return The key of the selected choice. */
| 53 | * @return The key of the selected choice. |
| 54 | */ |
| 55 | const std::string WeightedOptions::top() const |
| 56 | { |
| 57 | if (_totalWeight == 0) |
| 58 | { |
| 59 | return ""; |
| 60 | } |
| 61 | size_t max = 0; |
| 62 | std::map<std::string, size_t>::const_iterator i = _choices.begin(); |
| 63 | for (std::map<std::string, size_t>::const_iterator ii = _choices.begin(); ii != _choices.end(); ++ii) |
| 64 | { |
| 65 | if (ii->second >= max) |
| 66 | { |
| 67 | max = ii->second; |
| 68 | i = ii; |
| 69 | } |
| 70 | } |
| 71 | // We always have a valid iterator here. |
| 72 | return i->first; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Set an option's weight. |
no outgoing calls
no test coverage detected