ActiveLib
Loading...
Searching...
No Matches
Inventory.h
1
6#ifndef ACTIVE_SERIALISE_INVENTORY
7#define ACTIVE_SERIALISE_INVENTORY
8
9#include "Active/Serialise/Inventory/Entry.h"
10
11#include <unordered_map>
12#include <vector>
13
14namespace active::serialise {
15
19 class Inventory : public std::vector<Entry> {
20 public:
21
22 // MARK: - Types
23
25 using value = Entry;
27 using base = std::vector<value>;
29 using size_type = base::size_type;
31 using iterator = typename base::iterator;
33 using Option = std::optional<Inventory>;
35 using Item = value;
37 using ItemOption = std::optional<Inventory::Item>;
39 using Sequence = std::vector<std::pair<int16_t, const_iterator>>;
40
41 // MARK: - Constructors
42
46 Inventory() : base() {}
51 Inventory(base entries) : base(entries) { m_isFilled = true; }
52
53 // MARK: - Variables
54
56 bool isEveryItemAccepted = false;
57
58 // MARK: - Functions (const)
59
61 bool isFilled() const { return m_isFilled; }
66 size_type attributeSize(bool isRequiredOnly = false) const;
71 Sequence sequence() const;
72
73 // MARK: - Functions (mutating)
74
80 Inventory& withType(const std::type_info* ownerType);
86 Inventory& merge(const Inventory& inventory);
92 iterator registerIncoming(const Identity& identity);
96 void resetAvailable();
103 iterator findEntry(const Identity& identity, const std::type_info* owner = nullptr);
110 iterator findEntry(int16_t ind, const std::type_info* owner = nullptr);
118 bool setRequired(bool mustHave, int16_t ind, const std::type_info* owner = nullptr);
119
120 private:
122 bool m_isFilled = false;
123 };
124
125}
126
127#endif //ACTIVE_SERIALISE_INVENTORY
Definition Inventory.h:19
Sequence sequence() const
Definition Inventory.cpp:32
typename base::iterator iterator
Base storage class - entry keyed by ID/name.
Definition Inventory.h:31
std::optional< Inventory::Item > ItemOption
An optional inventory item.
Definition Inventory.h:37
size_type attributeSize(bool isRequiredOnly=false) const
Definition Inventory.cpp:20
bool isEveryItemAccepted
True if cargo with any item ID can be accepted by the package inventory.
Definition Inventory.h:56
Inventory & withType(const std::type_info *ownerType)
Definition Inventory.cpp:53
Inventory()
Definition Inventory.h:46
iterator findEntry(const Identity &identity, const std::type_info *owner=nullptr)
Definition Inventory.cpp:108
Entry value
Inventory value type, i.e. entries.
Definition Inventory.h:25
std::optional< Inventory > Option
An optional inventory.
Definition Inventory.h:33
iterator registerIncoming(const Identity &identity)
Definition Inventory.cpp:81
std::vector< value > base
Base storage class - entry keyed by ID/name.
Definition Inventory.h:27
bool isFilled() const
True if entries have been filled into the inventory.
Definition Inventory.h:61
void resetAvailable()
Definition Inventory.cpp:95
Inventory & merge(const Inventory &inventory)
Definition Inventory.cpp:66
Inventory(base entries)
Definition Inventory.h:51
base::size_type size_type
Inventory size_type.
Definition Inventory.h:29
std::vector< std::pair< int16_t, const_iterator > > Sequence
Inventory contents sequenced by the entry index (NB: invalidated if the inventory changes)
Definition Inventory.h:39
bool setRequired(bool mustHave, int16_t ind, const std::type_info *owner=nullptr)
Definition Inventory.cpp:139
Definition Cargo.h:12
Definition Entry.h:20
Definition Identity.h:18