OpenXcom  1.0
Open-source clone of the original X-Com
ItemContainer.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 <yaml-cpp/yaml.h>
23 
24 namespace OpenXcom
25 {
26 
27 class Mod;
28 
35 {
36 private:
37  std::map<std::string, int> _qty;
38 public:
40  ItemContainer();
44  void load(const YAML::Node& node);
46  YAML::Node save() const;
48  void addItem(const std::string &id, int qty = 1);
50  void removeItem(const std::string &id, int qty = 1);
52  int getItem(const std::string &id) const;
54  int getTotalQuantity() const;
56  double getTotalSize(const Mod *mod) const;
58  std::map<std::string, int> *getContents();
59 };
60 
61 }
void addItem(const std::string &id, int qty=1)
Adds an item to the container.
Definition: ItemContainer.cpp:65
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
int getTotalQuantity() const
Gets the total quantity of items in the container.
Definition: ItemContainer.cpp:126
std::map< std::string, int > * getContents()
Gets all the items in the container.
Definition: ItemContainer.cpp:155
ItemContainer()
Creates an empty item container.
Definition: ItemContainer.cpp:29
Represents the items contained by a certain entity, like base stores, craft equipment, etc.
Definition: ItemContainer.h:34
~ItemContainer()
Cleans up the item container.
Definition: ItemContainer.cpp:36
int getItem(const std::string &id) const
Gets an item in the container.
Definition: ItemContainer.cpp:104
double getTotalSize(const Mod *mod) const
Gets the total size of items in the container.
Definition: ItemContainer.cpp:141
void load(const YAML::Node &node)
Loads the item container from YAML.
Definition: ItemContainer.cpp:44
void removeItem(const std::string &id, int qty=1)
Removes an item from the container.
Definition: ItemContainer.cpp:83
YAML::Node save() const
Saves the item container to YAML.
Definition: ItemContainer.cpp:53
Definition: BaseInfoState.cpp:40