OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::WeightedOptions Class Reference

Holds pairs of relative weights and IDs. More...

#include <WeightedOptions.h>

Public Member Functions

 WeightedOptions ()
 Create an empty set.
 
const std::string choose () const
 Select from among the items. More...
 
const std::string top () const
 Select the top item. More...
 
void set (const std::string &id, size_t weight)
 Set an option's weight. More...
 
bool empty () const
 Is this empty?
 
void clear ()
 Remove all entries.
 
void load (const YAML::Node &node)
 Update our list with data from YAML. More...
 
YAML::Node save () const
 Store our list in YAML. More...
 

Detailed Description

Holds pairs of relative weights and IDs.

It is used to store options and make a random choice between them.

Member Function Documentation

const std::string OpenXcom::WeightedOptions::choose ( ) const

Select from among the items.

Select a random choice from among the contents.

This MUST be called on non-empty objects. Each time this is called, the returned value can be different.

Returns
The key of the selected choice.
void OpenXcom::WeightedOptions::load ( const YAML::Node &  nd)

Update our list with data from YAML.

Add the weighted options from a YAML::Node to a WeightedOptions.

The weight option list is not replaced, only values in nd will be added / changed.

Parameters
ndThe YAML node (containing a map) with the new values.
YAML::Node OpenXcom::WeightedOptions::save ( ) const

Store our list in YAML.

Send the WeightedOption contents to a YAML::Emitter.

Returns
YAML node.
void OpenXcom::WeightedOptions::set ( const std::string &  id,
size_t  weight 
)

Set an option's weight.

If weight is set to 0, the option is removed from the list of choices. If id already exists, the new weight replaces the old one, otherwise id is added to the list of choices, with weight as the weight.

Parameters
idThe option name.
weightThe option's new weight.
const std::string OpenXcom::WeightedOptions::top ( ) const

Select the top item.

Select the most likely option.

This MUST be called on non-empty objects.

Returns
The key of the selected choice.

The documentation for this class was generated from the following files: