OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WeightedOptions.h
1 /*
2  * Copyright 2012 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_WEIGHTEDOPTIONS_H
20 #define OPENXCOM_WEIGHTEDOPTIONS_H
21 
22 #include <string>
23 #include <map>
24 #include <yaml-cpp/yaml.h>
25 
26 
27 namespace OpenXcom
28 {
29 
35 {
36 public:
38  WeightedOptions() : _totalWeight(0) { /* Empty by design. */ }
40  const std::string choose() const;
42  const std::string top() const;
44  void set(const std::string &id, size_t weight);
46  bool empty() const { return 0 == _totalWeight; }
48  void clear() { _totalWeight = 0; _choices.clear(); }
50  void load(const YAML::Node &node);
52  YAML::Node save() const;
53 private:
54  std::map<std::string, size_t> _choices;
55  size_t _totalWeight;
56 };
57 
58 }
59 #endif
WeightedOptions()
Create an empty set.
Definition: WeightedOptions.h:38
void clear()
Remove all entries.
Definition: WeightedOptions.h:48
const std::string top() const
Select the top item.
Definition: WeightedOptions.cpp:55
bool empty() const
Is this empty?
Definition: WeightedOptions.h:46
const std::string choose() const
Select from among the items.
Definition: WeightedOptions.cpp:32
void set(const std::string &id, size_t weight)
Set an option's weight.
Definition: WeightedOptions.cpp:83
Holds pairs of relative weights and IDs.
Definition: WeightedOptions.h:34
YAML::Node save() const
Store our list in YAML.
Definition: WeightedOptions.cpp:126
void load(const YAML::Node &node)
Update our list with data from YAML.
Definition: WeightedOptions.cpp:112