OpenXcom  1.0
Open-source clone of the original X-Com
WeightedOptions.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <string>
21 #include <map>
22 #include <vector>
23 #include <yaml-cpp/yaml.h>
24 
25 
26 namespace OpenXcom
27 {
28 
34 {
35 public:
37  WeightedOptions() : _totalWeight(0) { /* Empty by design. */ }
39  std::string choose() const;
41  void set(const std::string &id, size_t weight);
43  bool empty() const { return 0 == _totalWeight; }
45  void clear() { _totalWeight = 0; _choices.clear(); }
47  void load(const YAML::Node &node);
49  YAML::Node save() const;
51  std::vector<std::string> getNames();
52 private:
53  std::map<std::string, size_t> _choices;
54  size_t _totalWeight;
55 };
56 
57 }
std::string choose() const
Select from among the items.
Definition: WeightedOptions.cpp:31
WeightedOptions()
Create an empty set.
Definition: WeightedOptions.h:37
void clear()
Remove all entries.
Definition: WeightedOptions.h:45
YAML::Node save() const
Store our list in YAML.
Definition: WeightedOptions.cpp:100
bool empty() const
Is this empty?
Definition: WeightedOptions.h:43
std::vector< std::string > getNames()
Get the list of strings associated with these weights.
Definition: WeightedOptions.cpp:114
Holds pairs of relative weights and IDs.
Definition: WeightedOptions.h:33
void load(const YAML::Node &node)
Update our list with data from YAML.
Definition: WeightedOptions.cpp:86
Definition: BaseInfoState.cpp:40