/
Cargo.hpp
77 lines (61 loc) · 2.27 KB
/
Cargo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef H_CARGO
#define H_CARGO
#include <map>
#include "CargoType.hpp"
/** A collection of individual amounts of different CargoType's.
* This class should represent any random pile of stuff an entity
* (player, ship, base) happens to have.
*/
class Cargo {
public:
/** Create an empty Cargo container */
Cargo();
/** deconstructor */
~Cargo();
/** Add quantity cargo of type to this Cargo
* @param type reference to the CargoType to add
* @param quantity the amount of cargo to add
*/
void addCargo(const CargoType &type, const unsigned int quantity);
/** Add newCargo to the cargohold
* @param newCargo reference to another cargo to add.
*/
void addCargo(const Cargo &newCargo);
/** Removes cargo from this Cargo
* TODO: replace return with exceptions
* @param newCargo reference to the Cargo to remove.
* @return true when successfull, false on failure
*/
bool delCargo(const Cargo &newCargo);
/** Counts the amount of Caargo::const_iterator
* @param type reference to the CargoType to find
* @return the amount of CargoType in this Cargo
*/
unsigned int getCount(const CargoType &type) const;
/** check if the content of newCargo is in this Cargo
* @param newCargo Cargo that we wish to check for
* @return true if newCargo is in this Cargo, false on failure
*/
bool contains(const Cargo &newCargo) const;
std::string getName() const;
/** Compare one cargo to another
* @param that reference to the other cargo
* @return true when this and that are equal, false otherwise
*/
bool operator==(const Cargo &that) const;
/** XML representation of this Cargo
* @return XML compliant string representing this Cargo */
std::string getXML() const;
std::map<CargoType, unsigned int>::iterator begin();
std::map<CargoType, unsigned int>::const_iterator begin() const;
std::map<CargoType, unsigned int>::iterator end();
std::map<CargoType, unsigned int>::const_iterator end() const;
private:
/** Iterator datastructure iterator */
typedef std::map<CargoType, unsigned int>::iterator iterator;
/** Iterator datastructure const iterator */
typedef std::map<CargoType, unsigned int>::const_iterator const_iterator;
/** The datastructure holding the actual cargo itself. */
std::map<CargoType, unsigned int> cargo;
};
#endif // H_CARGO