4#include "../Containers/Vector.h"
5#include "../Foundation/StrongID.h"
9template <
typename Key,
typename Value,
typename Container>
11template <
typename Key,
typename Value>
20template <
typename Key,
typename Value>
31template <
typename Key,
typename Value,
typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
39 [[nodiscard]]
auto size()
const {
return items.size(); }
42 [[nodiscard]]
auto isEmpty()
const {
return items.isEmpty(); }
44 [[nodiscard]] Item* begin() {
return items.begin(); }
45 [[nodiscard]]
const Item* begin()
const {
return items.begin(); }
46 [[nodiscard]] Item* end() {
return items.end(); }
47 [[nodiscard]]
const Item* end()
const {
return items.end(); }
52 template <
typename ComparableToKey>
53 [[nodiscard]]
bool remove(
const ComparableToKey& key)
56 for (
auto& item : items)
60 return items.removeAt(idx);
74 return items.push_back(forward<Item>(item));
84 for (
auto& it : items)
86 if (it.key == item.key)
88 it.value =
move(item.value);
92 if (items.push_back(forward<Item>(item)))
94 return &items.back().value;
105 if (items.push_back({Key::generateUniqueKey(*this), forward<Value>(value)}))
107 return &items.back().key;
113 template <
typename ComparableToKey>
114 [[nodiscard]]
bool contains(
const ComparableToKey& key)
const
116 for (
auto& item : items)
129 template <
typename ComparableToKey>
130 [[nodiscard]]
bool contains(
const ComparableToKey& key,
const Value*& outValue)
const
132 for (
auto& item : items)
136 outValue = &item.value;
146 template <
typename ComparableToKey>
147 [[nodiscard]]
bool contains(
const ComparableToKey& key, Value*& outValue)
149 for (
auto& item : items)
153 outValue = &item.value;
162 template <
typename ComparableToKey>
163 [[nodiscard]]
const Value*
get(
const ComparableToKey& key)
const
165 for (
auto& item : items)
177 template <
typename ComparableToKey>
178 [[nodiscard]] Value*
get(
const ComparableToKey& key)
180 for (
auto& item : items)
192 template <
typename ComparableToKey>
195 for (
auto& item : items)
202 if (items.push_back({key, Value()}))
204 return &items.back().value;
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition: Compiler.h:269
A map holding VectorMapItem key-value pairs in an unsorted Vector.
Definition: VectorMap.h:33
auto size() const
Return the number of key-value pairs in the map.
Definition: VectorMap.h:39
Key * insertValueUniqueKey(Value &&value)
Inserts a new value, automatically generating key with Key::generateUniqueKey (works for StrongID for...
Definition: VectorMap.h:103
auto isEmpty() const
Check if the map is empty.
Definition: VectorMap.h:42
bool contains(const ComparableToKey &key, Value *&outValue)
Check if the given key is contained in the map.
Definition: VectorMap.h:147
const Value * get(const ComparableToKey &key) const
Get the Value associated to the given key.
Definition: VectorMap.h:163
bool contains(const ComparableToKey &key) const
Check if the given key is contained in the map.
Definition: VectorMap.h:114
bool insertIfNotExists(Item &&item)
Inserts an item if it doesn't exist already.
Definition: VectorMap.h:70
Value * getOrCreate(const ComparableToKey &key)
Get the value associated to the given key, or creates a new one if needed.
Definition: VectorMap.h:193
Value * get(const ComparableToKey &key)
Get the Value associated to the given key.
Definition: VectorMap.h:178
bool remove(const ComparableToKey &key)
Remove an item with matching key from the Map.
Definition: VectorMap.h:53
Value * insertOverwrite(Item &&item)
Insert an item, overwriting the potentially already existing one.
Definition: VectorMap.h:82
bool contains(const ComparableToKey &key, const Value *&outValue) const
Check if the given key is contained in the map.
Definition: VectorMap.h:130
The single item of VectorMap, holding a Key and Value.
Definition: VectorMap.h:22
Key key
Key item value.
Definition: VectorMap.h:23
Value value
Map item value.
Definition: VectorMap.h:24