4#include "../Containers/StrongID.h"
5#include "../Containers/Vector.h"
6#include "ContainersExport.h"
10template <
typename Key,
typename Value,
typename Container>
12template <
typename Key,
typename Value>
21template <
typename Key,
typename Value>
34template <
typename Key,
typename Value,
typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
42 [[nodiscard]]
auto size()
const {
return items.size(); }
45 [[nodiscard]]
auto isEmpty()
const {
return items.isEmpty(); }
47 [[nodiscard]] Item* begin() {
return items.begin(); }
48 [[nodiscard]]
const Item* begin()
const {
return items.begin(); }
49 [[nodiscard]] Item* end() {
return items.end(); }
50 [[nodiscard]]
const Item* end()
const {
return items.end(); }
55 template <
typename ComparableToKey>
56 [[nodiscard]]
bool remove(
const ComparableToKey& key)
59 for (
auto& item : items)
63 return items.removeAt(idx);
87 for (
auto& it : items)
89 if (it.key == item.key)
91 it.value =
move(item.value);
97 return &items.back().value;
108 if (items.push_back({Key::generateUniqueKey(*this), forward<Value>(value)}))
110 return &items.back().key;
116 template <
typename ComparableToKey>
117 [[nodiscard]]
bool contains(
const ComparableToKey& key)
const
119 for (
auto& item : items)
132 template <
typename ComparableToKey>
133 [[nodiscard]]
bool contains(
const ComparableToKey& key,
const Value*& outValue)
const
135 for (
auto& item : items)
139 outValue = &item.value;
149 template <
typename ComparableToKey>
150 [[nodiscard]]
bool contains(
const ComparableToKey& key, Value*& outValue)
152 for (
auto& item : items)
156 outValue = &item.value;
165 template <
typename ComparableToKey>
166 [[nodiscard]]
const Value*
get(
const ComparableToKey& key)
const
168 for (
auto& item : items)
180 template <
typename ComparableToKey>
181 [[nodiscard]] Value*
get(
const ComparableToKey& key)
183 for (
auto& item : items)
195 template <
typename ComparableToKey>
198 for (
auto& item : items)
205 if (items.push_back({key, Value()}))
207 return &items.back().value;
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:273
constexpr T && forward(typename TypeTraits::RemoveReference< T >::type &value)
Forwards an lvalue or an rvalue as an rvalue reference.
Definition Compiler.h:276
The single item of VectorMap, holding a Key and Value.
Definition VectorMap.h:23
Key key
Key item value.
Definition VectorMap.h:24
Value value
Map item value.
Definition VectorMap.h:25
A map holding VectorMapItem key-value pairs in an unsorted Vector.
Definition VectorMap.h:36
auto size() const
Return the number of key-value pairs in the map.
Definition VectorMap.h:42
Key * insertValueUniqueKey(Value &&value)
Inserts a new value, automatically generating key with Key::generateUniqueKey (works for StrongID for...
Definition VectorMap.h:106
auto isEmpty() const
Check if the map is empty.
Definition VectorMap.h:45
bool contains(const ComparableToKey &key, Value *&outValue)
Check if the given key is contained in the map.
Definition VectorMap.h:150
const Value * get(const ComparableToKey &key) const
Get the Value associated to the given key.
Definition VectorMap.h:166
bool contains(const ComparableToKey &key) const
Check if the given key is contained in the map.
Definition VectorMap.h:117
bool insertIfNotExists(Item &&item)
Inserts an item if it doesn't exist already.
Definition VectorMap.h:73
Value * getOrCreate(const ComparableToKey &key)
Get the value associated to the given key, or creates a new one if needed.
Definition VectorMap.h:196
Value * get(const ComparableToKey &key)
Get the Value associated to the given key.
Definition VectorMap.h:181
bool remove(const ComparableToKey &key)
Remove an item with matching key from the Map.
Definition VectorMap.h:56
Value * insertOverwrite(Item &&item)
Insert an item, overwriting the potentially already existing one.
Definition VectorMap.h:85
bool contains(const ComparableToKey &key, const Value *&outValue) const
Check if the given key is contained in the map.
Definition VectorMap.h:133