summaryrefslogtreecommitdiff
path: root/src/cargo_type.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-06-27 21:06:58 +0000
committerfrosch <frosch@openttd.org>2009-06-27 21:06:58 +0000
commita288e4d82ff85819aa49061d66ee7e0cfd87e802 (patch)
treedcb119ed56cd690290a226e44feaf430ff4f14de /src/cargo_type.h
parent9b070b5405d11c74d89a747e912e627e39850f7c (diff)
downloadopenttd-a288e4d82ff85819aa49061d66ee7e0cfd87e802.tar.xz
(svn r16678) -Codechange: Turn CargoArray into a class, so one does not have to deal with sizeof() wrt. typedef-ed arrays.
Diffstat (limited to 'src/cargo_type.h')
-rw-r--r--src/cargo_type.h28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/cargo_type.h b/src/cargo_type.h
index 94bc9dbb6..4fd424d35 100644
--- a/src/cargo_type.h
+++ b/src/cargo_type.h
@@ -55,7 +55,31 @@ enum CargoTypes {
CT_INVALID = 0xFF
};
-/** Array for storing amounts of cargo */
-typedef uint CargoArray[NUM_CARGO];
+/** Class for storing amounts of cargo */
+struct CargoArray {
+private:
+ uint amount[NUM_CARGO];
+
+public:
+ FORCEINLINE CargoArray()
+ {
+ this->Clear();
+ }
+
+ FORCEINLINE void Clear()
+ {
+ memset(this->amount, 0, sizeof(this->amount));
+ }
+
+ FORCEINLINE uint &operator[](CargoID cargo)
+ {
+ return this->amount[cargo];
+ }
+
+ FORCEINLINE const uint &operator[](CargoID cargo) const
+ {
+ return this->amount[cargo];
+ }
+};
#endif /* CARGO_TYPE_H */