Murl::ObjectMap< KeyType, DataType, HashFunc > Class Template Reference

A generic map template class for non-moveable objects eg. NonCopyable classes. More...

#include "murl_object_map.h"

Inheritance diagram for Murl::ObjectMap< KeyType, DataType, HashFunc >:

Public Types

using KeyValueType = KeyType
 The template key parameter value type.
 
using ValueType = DataType
 The template data parameter value type.
 
- Public Types inherited from Murl::MapBase< KeyType, DataType, ObjectArray< DataType >, StdHash< KeyType > >
using KeyValueType = KeyType
 The template key parameter value type.
 
using ValueType = DataType
 The template data parameter value type.
 
using KeyIndexType = Index< KeyType, StdHash< KeyType > >
 Definition of the key index type.
 
using KeyConstIterator = typename KeyIndexType::ConstIterator
 Definition of the const key iterator.
 
using ConstIterator = typename ArrayType::ConstIterator
 Definition of the const iterator.
 
using Iterator = typename ArrayType::Iterator
 Definition of the iterator.
 

Public Member Functions

 ObjectMap ()
 The default constructor. More...
 
 ObjectMap (const ObjectMap &map)
 The copy constructor. More...
 
DataType & Add (const KeyType &key, DataType *value)
 Add a key/value pair to the map. More...
 
DataType & Insert (SInt32 index, const KeyType &key, DataType *value)
 Insert a key/value pair into the map at a given position. More...
 
template<class DataTypeT >
DataTypeT & Create (const KeyType &key)
 Create and add an value at the specified key. More...
 
DataType & Set (SInt32 index, DataType *item)
 Set a new allocated value item at a given position. More...
 
DataType * PopDetach ()
 Removes the item from the top position and giving up ownership. More...
 
DataType * Detach (SInt32 index)
 Removes the item at a given position and giving up ownership. More...
 
DataType * Swap (SInt32 index, DataType *newItem)
 Swap the item at a given position with a new allocated item. More...
 
DataType & Add (const KeyType &key)
 Add a new key/value pair to the map. More...
 
DataType & Add (const KeyType &key, const DataType &value)
 Add a key/value pair to the map. More...
 
DataType & Insert (SInt32 index, const KeyType &key)
 Insert a new key/value pair into the map at a given position. More...
 
DataType & Insert (SInt32 index, const KeyType &key, const DataType &value)
 Insert a key/value pair into the map at a given position. More...
 
void Swap (MapBase &other)
 Exchange the content of the map with a given second one. More...
 
- Public Member Functions inherited from Murl::MapBase< KeyType, DataType, ObjectArray< DataType >, StdHash< KeyType > >
void Clear ()
 Clear the map and remove the underlying storage.
 
void Empty ()
 Empty the map, but keep the underlying storage.
 
void Shrink ()
 Shrink the map so that the underlying key and value storage is only as large as necessary.
 
void Trim (SInt32 n)
 Reduce the map to a given number of items. More...
 
void Drop (SInt32 n=1)
 Reduce the map by removing a given number of items from the end. More...
 
void Reserve (SInt32 n)
 Reserve storage space. More...
 
void Sweep ()
 Remove any unlinked pairs from the map.
 
void SetKey (SInt32 index, const KeyType &key)
 Set the key of a given index. More...
 
void Swap (MapBase &other)
 Exchange the content of the map with a given second one. More...
 
DataType & Add (const KeyType &key)
 Add a new key/value pair to the map. More...
 
DataType & Add (const KeyType &key, const DataType &value)
 Add a key/value pair to the map. More...
 
DataType & Put (const KeyType &key)
 Add a new key/value pair to the map, replacing an unlinked element if present. More...
 
SInt32 Put (const KeyType &key, const DataType &value)
 Add a key/value pair to the map, replacing an unlinked element if present. More...
 
DataType & Insert (SInt32 index, const KeyType &key)
 Insert a new key/value pair into the map at a given position. More...
 
DataType & Insert (SInt32 index, const KeyType &key, const DataType &value)
 Insert a key/value pair into the map at a given position. More...
 
void Unlink (SInt32 index)
 Unlink the pair at a given index. More...
 
SInt32 UnlinkKey (const KeyType &key)
 Unlink all pairs matching a given key. More...
 
SInt32 UnlinkKey (const KeyType &key, UInt32 hash)
 Unlink all pairs matching a given key, using a precomputed hash value. More...
 
Bool IsUnlinked (SInt32 index) const
 Check if the pair at a given index is unlinked. More...
 
Bool HasUnlinked () const
 Check if the map has unlinked items. More...
 
SInt32Array GetUnlinked () const
 Get an array of indices of all unlinked items. More...
 
void Remove (SInt32 index)
 Remove the key/value pair at a given position from the map. More...
 
void Remove (SInt32 index, SInt32 count)
 Remove a number of key/value pairs from the map at a given starting position. More...
 
void Remove (const SInt32 *sortedIndices, SInt32 count)
 Remove a number of key/value pairs from the map at given positions. More...
 
void Remove (const SInt32Array &sortedIndices)
 Remove a number of key/value pairs from the map at given positions. More...
 
SInt32 RemoveKey (const KeyType &key)
 Remove all pairs from the map that match a given key. More...
 
SInt32 Find (const KeyType &key) const
 Find the first occurrence of a given key in the map. More...
 
SInt32 Find (const KeyType &key, UInt32 hash) const
 Find the first occurrence of a given key in the map, using a precomputed hash value. More...
 
SInt32 FindLast (const KeyType &key) const
 Find the last occurrence of a given key in the map. More...
 
SInt32 FindLast (const KeyType &key, UInt32 hash) const
 Find the last occurrence of a given key in the map, using a precomputed hash value. More...
 
SInt32 FindNext (SInt32 index) const
 Find the next occurrence of a key that is specified by a given index. More...
 
SInt32 FindPrev (SInt32 index) const
 Find the previous occurrence of a key that is specified by a given index. More...
 
SInt32 FindAdd (const KeyType &key)
 Find the first occurrence of a given key in the map, or add a new pair if the key was not found. More...
 
SInt32 FindAdd (const KeyType &key, const DataType &value)
 Find the first occurrence of a given key in the map, or add a new pair if the key was not found. More...
 
SInt32 FindPut (const KeyType &key)
 Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More...
 
SInt32 FindPut (const KeyType &key, const DataType &value)
 Find the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More...
 
DataType & Get (const KeyType &key)
 Get a reference to the first occurrence of a given key in the map. More...
 
const DataType & Get (const KeyType &key) const
 Get a const reference to the first occurrence of a given key in the map. More...
 
const DataType & Get (const KeyType &key, const DataType &defaultValue) const
 Get a const reference to the first occurrence of a given key in the map. More...
 
DataType * GetPtr (const KeyType &key)
 Get a pointer to the first occurrence of a given key in the map. More...
 
const DataType * GetPtr (const KeyType &key) const
 Get a const pointer to the first occurrence of a given key in the map. More...
 
DataType & GetAdd (const KeyType &key)
 Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found. More...
 
DataType & GetAdd (const KeyType &key, const DataType &value)
 Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found. More...
 
DataType & GetPut (const KeyType &key)
 Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More...
 
DataType & GetPut (const KeyType &key, const DataType &value)
 Get a reference to the first occurrence of a given key in the map, or add a new pair if the key was not found, hereby replacing an unlinked element if possible. More...
 
const KeyType & GetKey (SInt32 index) const
 Get a const reference to the key at a given index. More...
 
const KeyIndexTypeGetIndex () const
 Get a const reference to the key storage. More...
 
const Array< KeyType > & GetKeys () const
 Get a const reference to the array of keys. More...
 
ObjectArray< DataType > & GetValues ()
 Get a reference to the array of values. More...
 
const ObjectArray< DataType > & GetValues () const
 Get a const reference to the array of values. More...
 
Bool IsIndexValid (SInt32 index) const
 Check if a given index is a valid index. More...
 
const DataType & operator[] (SInt32 index) const
 Get a const reference to the value at a given index. More...
 
DataType & operator[] (SInt32 index)
 Get a reference to the value at a given index. More...
 
DataType & Front ()
 Get a reference to the first value in the storage. More...
 
const DataType & Front () const
 Get a const reference to the first value in the storage. More...
 
const KeyType & FrontKey () const
 Get a const reference to the first key in the storage. More...
 
DataType & Back ()
 Get a reference to the last value in the storage. More...
 
const DataType & Back () const
 Get a const reference to the last value in the storage. More...
 
const KeyType & BackKey () const
 Get a const reference to the last key in the storage. More...
 
DataType & Bottom ()
 Get a reference to the first value in the storage. More...
 
const DataType & Bottom () const
 Get a const reference to the first value in the storage. More...
 
const KeyType & BottomKey () const
 Get a const reference to the first key in the storage. More...
 
DataType & Top ()
 Get a reference to the last value in the storage. More...
 
const DataType & Top () const
 Get a const reference to the last value in the storage. More...
 
const KeyType & TopKey () const
 Get a const reference to the last key in the storage. More...
 
KeyType PopKey ()
 Remove the last key/value pair from the map and return its key. More...
 
SInt32 GetAlloc () const
 Get the number of actually allocated pairs. More...
 
SInt32 GetCount () const
 Get the number of items in the map. More...
 
UInt32 GetCountUInt32 () const
 Get the number of items in the map. More...
 
Bool IsEmpty () const
 Check if the map is empty. More...
 
KeyConstIterator KeyBegin () const
 Get the const key iterator to the first element. More...
 
KeyConstIterator KeyEnd () const
 Get the const key iterator next to the last element. More...
 
KeyConstIterator KeyGetIter (SInt32 index) const
 Get the const key iterator of a specified index. More...
 
ConstIterator Begin () const
 Get the const iterator to the first element. More...
 
Iterator Begin ()
 Get the iterator to the first element. More...
 
ConstIterator End () const
 Get the const iterator next to the last element. More...
 
Iterator End ()
 Get the iterator next to the last element. More...
 
ConstIterator GetIter (SInt32 index) const
 Get the const iterator of a specified index. More...
 
Iterator GetIter (SInt32 index)
 Get the iterator of a specified index. More...
 
Bool IsEqual (const MapBase &other) const
 Compare the map to another one. More...
 
bool operator== (const MapBase &rhs) const
 The "equal to" comparison operator, calls IsEqual(). More...
 
bool operator!= (const MapBase &rhs) const
 The "not equal to" comparison operator, calls IsEqual(). More...
 

Detailed Description

template<class KeyType, class DataType, class HashFunc = StdHash<KeyType>>
class Murl::ObjectMap< KeyType, DataType, HashFunc >

A generic map template class for non-moveable objects eg. NonCopyable classes.

See MapBase class for all map methods.
A map stores a number of key/value pairs, where the keys do not have to be unique.
The object map class uses pointers to the value objects, this ensures that the object's memory location is unchanged when modifying the map.
This class is based on the NTL ArrayMap container, see http://www.ultimatepp.org

Template Parameters
KeyTypeThe key's data type of the map.
DataTypeThe value's data type of the map.
HashFuncThe hash function of the key.

Constructor & Destructor Documentation

◆ ObjectMap() [1/2]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
Murl::ObjectMap< KeyType, DataType, HashFunc >::ObjectMap ( )
inline

The default constructor.

Create an empty map.

◆ ObjectMap() [2/2]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
Murl::ObjectMap< KeyType, DataType, HashFunc >::ObjectMap ( const ObjectMap< KeyType, DataType, HashFunc > &  map)
inline

The copy constructor.

Parameters
mapThe map object to copy.

Member Function Documentation

◆ Add() [1/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::ObjectMap< KeyType, DataType, HashFunc >::Add ( const KeyType &  key,
DataType *  value 
)
inline

Add a key/value pair to the map.

The map takes the ownership of the value item.

Parameters
keyThe key under which the value can be retrieved.
valueThe value to add.
Returns
A reference to the newly constructed value.

◆ Insert() [1/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::ObjectMap< KeyType, DataType, HashFunc >::Insert ( SInt32  index,
const KeyType &  key,
DataType *  value 
)
inline

Insert a key/value pair into the map at a given position.

The map takes the ownership of the value item.

Parameters
indexThe index where to insert the new pair.
keyThe key under which the value can be retrieved.
valueThe reference value to insert.
Returns
A reference to the newly constructed value.

◆ Create()

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
template<class DataTypeT >
DataTypeT& Murl::ObjectMap< KeyType, DataType, HashFunc >::Create ( const KeyType &  key)
inline

Create and add an value at the specified key.

Template Parameters
DataTypeTThe type of object to create.
Parameters
keyThe key under which the value can be retrieved.
Returns
A reference to the newly created item.

◆ Set()

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::ObjectMap< KeyType, DataType, HashFunc >::Set ( SInt32  index,
DataType *  item 
)
inline

Set a new allocated value item at a given position.

The map takes the ownership of the value item.

Parameters
indexThe zero-based index of the item to set.
itemThe new allocated item to set.
Returns
A reference to the item.

◆ PopDetach()

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType* Murl::ObjectMap< KeyType, DataType, HashFunc >::PopDetach ( )
inline

Removes the item from the top position and giving up ownership.

(!) The client is responsible for deletion of the returned item.

Returns
The pointer to the heap allocated item.

◆ Detach()

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType* Murl::ObjectMap< KeyType, DataType, HashFunc >::Detach ( SInt32  index)
inline

Removes the item at a given position and giving up ownership.

(!) The client is responsible for deletion of the returned item.

Parameters
indexThe zero-based index of the item to remove.
Returns
The pointer to the heap allocated item.

◆ Swap() [1/2]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType* Murl::ObjectMap< KeyType, DataType, HashFunc >::Swap ( SInt32  index,
DataType *  newItem 
)
inline

Swap the item at a given position with a new allocated item.

(!) The client is responsible for deletion of the returned item.

Parameters
indexThe zero-based index of the item to swap.
newItemThe new allocated item to swap into.
Returns
The pointer to the swapped-out heap allocated item.

◆ Add() [2/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Add
inline

Add a new key/value pair to the map.

The newly added value is initialized using the value type's default constructor.

Parameters
keyThe key under which the value can be retrieved.
Returns
A reference to the newly constructed value.

◆ Add() [3/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Add
inline

Add a key/value pair to the map.

The newly added value is initialized using the given reference value's copy constructor.

Parameters
keyThe key under which the value can be retrieved.
valueThe reference value to add.
Returns
A reference to the newly constructed value.

◆ Insert() [2/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Insert
inline

Insert a new key/value pair into the map at a given position.

The newly added value is initialized using the value type's default constructor.

Parameters
indexThe index where to insert the new pair.
keyThe key under which the value can be retrieved.
Returns
A reference to the newly constructed value.

◆ Insert() [3/3]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
DataType& Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Insert
inline

Insert a key/value pair into the map at a given position.

The newly added value is initialized using the given reference value's copy constructor.

Parameters
indexThe index where to insert the new pair.
keyThe key under which the value can be retrieved.
valueThe reference value to insert.
Returns
A reference to the newly constructed value.

◆ Swap() [2/2]

template<class KeyType , class DataType , class HashFunc = StdHash<KeyType>>
void Murl::MapBase< KeyType, DataType, ArrayType, HashFunc >::Swap
inline

Exchange the content of the map with a given second one.

Parameters
otherThe second map.

The documentation for this class was generated from the following file:
  • murl_object_map.h


Copyright © 2011-2024 Spraylight GmbH.