]> git.localhorst.tv Git - blobs.git/blob - src/creature/Composition.hpp
lose weight through exercise
[blobs.git] / src / creature / Composition.hpp
1 #ifndef BLOBLS_CREATURE_COMPOSITION_HPP_
2 #define BLOBLS_CREATURE_COMPOSITION_HPP_
3
4 #include <vector>
5
6
7 namespace blobs {
8 namespace creature {
9
10 class Composition {
11
12 public:
13         struct Component {
14                 int resource;
15                 double value;
16                 Component(int r, double v)
17                 : resource(r), value(v) { }
18         };
19
20 public:
21         Composition();
22         ~Composition();
23
24         Composition(const Composition &) = default;
25         Composition &operator =(const Composition &) = default;
26
27         Composition(Composition &&) = default;
28         Composition &operator =(Composition &&) = default;
29
30 public:
31         void Add(int res, double amount);
32         bool Has(int res) const noexcept;
33         double Get(int res) const noexcept;
34         double TotalMass() const noexcept { return total_mass; }
35
36 public:
37         std::vector<Component>::size_type size() const noexcept { return components.size(); }
38         std::vector<Component>::iterator begin() noexcept { return components.begin(); }
39         std::vector<Component>::iterator end() noexcept { return components.end(); }
40         std::vector<Component>::const_iterator begin() const noexcept { return components.begin(); }
41         std::vector<Component>::const_iterator end() const noexcept { return components.end(); }
42         std::vector<Component>::const_iterator cbegin() noexcept { return components.cbegin(); }
43         std::vector<Component>::const_iterator cend() noexcept { return components.cend(); }
44
45 private:
46         std::vector<Component> components;
47         double total_mass;
48
49 };
50
51 }
52 }
53
54 #endif