13 #ifndef _SMING_CORE_DATA_OBJECT_MAP_H_ 14 #define _SMING_CORE_DATA_OBJECT_MAP_H_ 71 const K& getKey()
const 81 Value& operator=(V* newValue)
83 map.
set(key, newValue);
127 return entries.count();
135 const K& keyAt(
unsigned idx)
const 137 return entries[idx].key;
145 K& keyAt(
unsigned idx)
147 return entries[idx].key;
156 const V* valueAt(
unsigned idx)
const 158 return entries[idx].value;
167 Value valueAt(
unsigned idx)
169 return Value(*
this, entries[idx].key);
200 Value
get(
const K& key)
202 return Value(*
this, key);
209 void set(
const K& key, V* value)
213 delete entries[i].value;
214 entries[i].value = value;
216 entries.addElement(
new Entry(key, value));
229 return (index < 0) ?
nullptr : entries[index].value;
239 for(
unsigned i = 0; i < entries.count(); i++) {
240 if(entries[i].key == key) {
263 entries.remove(index);
271 bool remove(
const K& key)
303 if(index < entries.count()) {
304 value = entries[index].value;
305 entries[index].value =
nullptr;
306 entries.remove(index);
327 Entry(
const K& key, V* value) : key(key), value(value)
344 #endif // _SMING_CORE_DATA_OBJECT_MAP_H_ void removeAt(unsigned index)
Remove entry at given index.
Definition: ObjectMap.h:261
V * extract()
Get the value for a given key and remove it from the map, without destroying it.
Definition: ObjectMap.h:111
Implementation of a HashMap for owned objects, i.e. anything created with new().
Definition: ObjectMap.h:48
bool contains(const K &key) const
Check if a key is contained within this map.
Definition: ObjectMap.h:252
Class to provide safe access to mapped value.
Definition: ObjectMap.h:64
void set(const K &key, V *value)
Set a key value.
Definition: ObjectMap.h:209
Value operator[](const K &key)
Access map entry by reference.
Definition: ObjectMap.h:190
bool remove(const K &key)
Remove a key from this map.
Definition: ObjectMap.h:271
void clear()
Clear the map of all entries.
Definition: ObjectMap.h:314
int indexOf(const K &key) const
Get the index of a key.
Definition: ObjectMap.h:237
unsigned count() const
Get the number of entries in this map.
Definition: ObjectMap.h:125
V * extractAt(unsigned index)
Get the value at a given index and remove it from the map, without destroying it. ...
Definition: ObjectMap.h:300
An entry in the ObjectMap.
Definition: ObjectMap.h:323
V * extract(const K &key)
Get the value for a given key and remove it from the map, without destroying it.
Definition: ObjectMap.h:288
const V * operator[](const K &key) const
Get value for given key, if it exists.
Definition: ObjectMap.h:178
V * find(const K &key) const
Find the value for a given key, if it exists.
Definition: ObjectMap.h:226