|
unsigned | count () const |
| Get the number of entries in this map. More...
|
|
const K & | keyAt (unsigned idx) const |
|
K & | keyAt (unsigned idx) |
|
const V * | valueAt (unsigned idx) const |
|
Value | valueAt (unsigned idx) |
|
const V * | operator[] (const K &key) const |
| Get value for given key, if it exists. More...
|
|
Value | operator[] (const K &key) |
| Access map entry by reference. More...
|
|
Value | get (const K &key) |
| Get map entry value. More...
|
|
void | set (const K &key, V *value) |
| Set a key value. More...
|
|
V * | find (const K &key) const |
| Find the value for a given key, if it exists. More...
|
|
int | indexOf (const K &key) const |
| Get the index of a key. More...
|
|
bool | contains (const K &key) const |
| Check if a key is contained within this map. More...
|
|
void | removeAt (unsigned index) |
| Remove entry at given index. More...
|
|
bool | remove (const K &key) |
| Remove a key from this map. More...
|
|
V * | extract (const K &key) |
| Get the value for a given key and remove it from the map, without destroying it. More...
|
|
V * | extractAt (unsigned index) |
| Get the value at a given index and remove it from the map, without destroying it. More...
|
|
void | clear () |
| Clear the map of all entries. More...
|
|
template<typename K, typename V>
class ObjectMap< K, V >
Implementation of a HashMap for owned objects, i.e. anything created with new().
- Note
- Once added to the map the object is destroyed when no longer required.
Example:
void test()
{
MyType* object1 = new MyType();
if (map["key1"] == nullptr) {
map["key1"] = object1;
}
MyType* object2 = new MyType();
map["key1"] = object2;
auto value = map["key1"];
value = new MyType();
value = nullptr;
value.remove();
map["key1"] = new MyType();
map["key2"] = new MyType();
}