OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ItemContainer.h
1 /*
2  * Copyright 2010-2014 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_ITEMCONTAINER_H
20 #define OPENXCOM_ITEMCONTAINER_H
21 
22 #include <string>
23 #include <map>
24 #include <yaml-cpp/yaml.h>
25 
26 namespace OpenXcom
27 {
28 
29 class Ruleset;
30 
37 {
38 private:
39  std::map<std::string, int> _qty;
40 public:
42  ItemContainer();
46  void load(const YAML::Node& node);
48  YAML::Node save() const;
50  void addItem(const std::string &id, int qty = 1);
52  void removeItem(const std::string &id, int qty = 1);
54  int getItem(const std::string &id) const;
56  int getTotalQuantity() const;
58  double getTotalSize(const Ruleset *rule) const;
60  std::map<std::string, int> *getContents();
61 };
62 
63 }
64 
65 #endif
void addItem(const std::string &id, int qty=1)
Adds an item to the container.
Definition: ItemContainer.cpp:65
YAML::Node save() const
Saves the item container to YAML.
Definition: ItemContainer.cpp:53
std::map< std::string, int > * getContents()
Gets all the items in the container.
Definition: ItemContainer.cpp:155
int getItem(const std::string &id) const
Gets an item in the container.
Definition: ItemContainer.cpp:104
ItemContainer()
Creates an empty item container.
Definition: ItemContainer.cpp:29
Set of rules and stats for a game.
Definition: Ruleset.h:69
Represents the items contained by a certain entity, like base stores, craft equipment, etc.
Definition: ItemContainer.h:36
~ItemContainer()
Cleans up the item container.
Definition: ItemContainer.cpp:36
int getTotalQuantity() const
Gets the total quantity of items in the container.
Definition: ItemContainer.cpp:126
void load(const YAML::Node &node)
Loads the item container from YAML.
Definition: ItemContainer.cpp:44
double getTotalSize(const Ruleset *rule) const
Gets the total size of items in the container.
Definition: ItemContainer.cpp:141
void removeItem(const std::string &id, int qty=1)
Removes an item from the container.
Definition: ItemContainer.cpp:83