OpenXcom  1.0
Open-source clone of the original X-Com
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.
 
std::string choose () const
 Select from among the items. 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...
 
std::vector< std::string > getNames ()
 Get the list of strings associated with these weights. 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

◆ choose()

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.

◆ getNames()

std::vector< std::string > OpenXcom::WeightedOptions::getNames ( )

Get the list of strings associated with these weights.

Returns
the list of strings in these weights.

◆ load()

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.

◆ save()

YAML::Node OpenXcom::WeightedOptions::save ( ) const

Store our list in YAML.

Send the WeightedOption contents to a YAML::Emitter.

Returns
YAML node.

◆ set()

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.

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