Chemical Data Processing Library C++ API - Version 1.1.1
Public Types | Public Member Functions | Protected Member Functions | List of all members
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc > Class Template Reference

A unique sorted associative container that maps keys to values. More...

#include <Map.hpp>

+ Inheritance diagram for CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >:

Public Types

typedef std::shared_ptr< MapSharedPointer
 A reference-counted smart pointer [SHPTR] for dynamically allocated Map instances. More...
 
typedef Key KeyType
 The type of the map's keys. More...
 
typedef Value ValueType
 The type of the mapped values. More...
 
typedef StorageType::value_type Entry
 The type of the key/value pairs stored in the map. More...
 
typedef StorageType::const_iterator ConstEntryIterator
 A constant iterator used to iterate over the entries of the map. More...
 
typedef StorageType::const_reverse_iterator ConstReverseEntryIterator
 A constant iterator used to iterate backwards over the entries of the map. More...
 
typedef StorageType::iterator EntryIterator
 A mutable iterator used to iterate over the entries of the map. More...
 
typedef StorageType::reverse_iterator ReverseEntryIterator
 A mutable iterator used to iterate backwards over the entries of the map. More...
 

Public Member Functions

 Map ()
 Creates an empty map. More...
 
 Map (const KeyCompFunc &func)
 Creates an empty map and uses func as key compare function. More...
 
template<typename InputIter >
 Map (const InputIter &first, const InputIter &last)
 Creates and initializes the map with copies of the key value pairs in the range [first, last). More...
 
template<typename InputIter >
 Map (const InputIter &first, const InputIter &last, const KeyCompFunc &func)
 Creates and initializes the map with copies of the key value pairs in the range [first, last) and uses func as key compare function. More...
 
virtual ~Map ()
 Virtual destructor. More...
 
StorageType & getData ()
 
const StorageType & getData () const
 
std::size_t getSize () const
 Returns the size (number of entries) of the map. More...
 
bool isEmpty () const
 Tells whether the map is empty (getSize() == 0). More...
 
void clear ()
 Erases all entries. More...
 
void swap (Map &map)
 Swaps the contents with map. More...
 
KeyCompFunc getKeyCompareFunction () const
 Returns the key compare function used by the map. More...
 
EntryIterator getEntry (const Key &key)
 Returns a mutable iterator pointing to the entry specified by key. More...
 
ConstEntryIterator getEntry (const Key &key) const
 Returns a constant iterator pointing to the entry specified by key. More...
 
bool containsEntry (const Key &key) const
 Tells whether the map contains an entry with the specified key. More...
 
Value & getValue (const Key &key)
 Returns a non-const reference to the value associated with the specified key. More...
 
Value & getValue (const Key &key, Value &def_value)
 Returns a non-const reference to the value associated with the specified key, or the value given by the second argument if the specified entry does not exist. More...
 
const Value & getValue (const Key &key) const
 Returns a const reference to the value associated with the specified key. More...
 
const Value & getValue (const Key &key, const Value &def_value) const
 Returns a const reference to the value associated with the specified key, or the value given by the second argument if the specified entry does not exist. More...
 
Value & operator[] (const Key &key)
 Returns a non-const reference to the value associated with the specified key. More...
 
const Value & operator[] (const Key &key) const
 Returns a const reference to the value associated with the specified key. More...
 
void removeEntry (const EntryIterator &it)
 Removes the entry pointed to by the iterator it from the map. More...
 
bool removeEntry (const Key &key)
 Removes the entry specified by key from the map. More...
 
void removeEntries (const EntryIterator &first, const EntryIterator &last)
 Removes all entries pointed to by the iterators in the range [first, last) from the map. More...
 
std::pair< EntryIterator, boolinsertEntry (const Entry &item)
 Tries to insert the key/value pair item into the map. More...
 
std::pair< EntryIterator, boolinsertEntry (const Key &key, const Value &value)
 Tries to insert a new entry with specified key and value into the map. More...
 
EntryIterator insertEntry (const EntryIterator &it, const Entry &item)
 Tries to insert the key/value pair item into the map and uses the iterator it as a hint for the insertion location. More...
 
EntryIterator insertEntry (const EntryIterator &it, const Key &key, const Value &value)
 Tries to insert a new entry with the specified key and value into the map and uses the iterator it as a hint for the insertion location. More...
 
EntryIterator setEntry (const Entry &item)
 Inserts a new entry or updates the value of an existing entry with the key and value given by item. More...
 
EntryIterator setEntry (const Key &key, const Value &value)
 Inserts a new entry or updates the value of an existing entry with the specified key and value. More...
 
template<typename InputIter >
void insertEntries (const InputIter &first, const InputIter &last)
 Tries to insert the key/value pairs in the range [first, last). More...
 
template<typename InputIter >
void setEntries (const InputIter &first, const InputIter &last)
 Inserts new entries or updates the value of existing entries using the key/value pairs in the range [first, last). More...
 
EntryIterator getLowerBound (const Key &key)
 Returns a mutable iterator pointing to the first entry whose key is not less than the specified key. More...
 
ConstEntryIterator getLowerBound (const Key &key) const
 Returns a constant iterator pointing to the first entry whose key is not less than the specified key. More...
 
EntryIterator getUpperBound (const Key &key)
 Returns a mutable iterator pointing to the first entry whose key is greater than the specified key. More...
 
ConstEntryIterator getUpperBound (const Key &key) const
 Returns a constant iterator pointing to the first entry whose key is greater than the specified key. More...
 
ConstEntryIterator getEntriesBegin () const
 Returns a constant iterator pointing to the beginning of the map. More...
 
EntryIterator getEntriesBegin ()
 Returns a mutable iterator pointing to the beginning of the map. More...
 
ConstEntryIterator getEntriesEnd () const
 Returns a constant iterator pointing to the end of the map. More...
 
EntryIterator getEntriesEnd ()
 Returns a mutable iterator pointing to the end of the map. More...
 
ConstEntryIterator begin () const
 Returns a constant iterator pointing to the beginning of the map. More...
 
EntryIterator begin ()
 Returns a mutable iterator pointing to the beginning of the map. More...
 
ConstEntryIterator end () const
 Returns a constant iterator pointing to the end of the map. More...
 
EntryIterator end ()
 Returns a mutable iterator pointing to the end of the map. More...
 
ConstReverseEntryIterator getEntriesReverseBegin () const
 Returns a constant iterator pointing to the beginning of the reversed map. More...
 
ReverseEntryIterator getEntriesReverseBegin ()
 Returns a mutable iterator pointing to the beginning of the reversed map. More...
 
ConstReverseEntryIterator getEntriesReverseEnd () const
 Returns a constant iterator pointing to the end of the reversed map. More...
 
ReverseEntryIterator getEntriesReverseEnd ()
 Returns a mutable iterator pointing to the end of the reversed map. More...
 

Protected Member Functions

virtual const char * getClassName () const
 Returns the name of the (derived) Map class. More...
 

Detailed Description

template<typename Key, typename Value, bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
class CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >

A unique sorted associative container that maps keys to values.

Since Map is a sorted associative container, it uses an ordering relation on its keys. Two keys are considered to be equivalent if neither one is less than the other. Map guarantees that the complexity for most operations is never worse than logarithmic, and the entries are always sorted in ascending order by key. It is also an unique associative container, meaning that no two entries have the same key. Map has the important property that inserting a new entry does not invalidate iterators that point to existing entries. Erasing an entry also does not invalidate any iterators, except, of course, for iterators that actually point to the entry that is being erased.

Template Parameters
KeyThe type of the map's keys.
ValueThe type of the mapped values.
AllowDefValuesWhether to return a default value or to throw an exception if a key/value entry is not present in the map.
KeyCompFuncThe type of a functor class used to establish the strictly weak ordering on the map's keys. The functor has to return true if the first argument is less than the second one, and false otherwise.

Member Typedef Documentation

◆ SharedPointer

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef std::shared_ptr<Map> CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::SharedPointer

A reference-counted smart pointer [SHPTR] for dynamically allocated Map instances.

◆ KeyType

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef Key CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::KeyType

The type of the map's keys.

◆ ValueType

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef Value CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ValueType

The type of the mapped values.

◆ Entry

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef StorageType::value_type CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::Entry

The type of the key/value pairs stored in the map.

The member Entry::first is the const key object of type Key and the member Entry::second is the associated value object of type Value.

◆ ConstEntryIterator

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef StorageType::const_iterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator

A constant iterator used to iterate over the entries of the map.

◆ ConstReverseEntryIterator

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef StorageType::const_reverse_iterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstReverseEntryIterator

A constant iterator used to iterate backwards over the entries of the map.

◆ EntryIterator

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef StorageType::iterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator

A mutable iterator used to iterate over the entries of the map.

◆ ReverseEntryIterator

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
typedef StorageType::reverse_iterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ReverseEntryIterator

A mutable iterator used to iterate backwards over the entries of the map.

Constructor & Destructor Documentation

◆ Map() [1/4]

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::Map ( )
inline

Creates an empty map.

◆ Map() [2/4]

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::Map ( const KeyCompFunc &  func)
inline

Creates an empty map and uses func as key compare function.

Parameters
funcThe key compare function to use.

◆ Map() [3/4]

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
template<typename InputIter >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::Map ( const InputIter &  first,
const InputIter &  last 
)
inline

Creates and initializes the map with copies of the key value pairs in the range [first, last).

Parameters
firstThe start of the range.
lastThe end of the range.

◆ Map() [4/4]

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
template<typename InputIter >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::Map ( const InputIter &  first,
const InputIter &  last,
const KeyCompFunc &  func 
)
inline

Creates and initializes the map with copies of the key value pairs in the range [first, last) and uses func as key compare function.

Parameters
firstThe start of the range.
lastThe end of the range.
funcThe key compare function to use.

◆ ~Map()

template<typename Key , typename Value , bool AllowDefValues = false, typename KeyCompFunc = std::less<Key>>
virtual CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::~Map ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ getData() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::StorageType & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getData

◆ getData() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
const CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::StorageType & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getData

◆ getSize()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
std::size_t CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getSize

Returns the size (number of entries) of the map.

Returns
The size of the map.

◆ isEmpty()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
bool CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::isEmpty

Tells whether the map is empty (getSize() == 0).

Returns
true if the map is empty, and false otherwise.

◆ clear()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::clear

Erases all entries.

◆ swap()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::swap ( Map< Key, Value, AllowDefValues, KeyCompFunc > &  map)

Swaps the contents with map.

Parameters
mapThe other map with which the contents will be exchanged.

◆ getKeyCompareFunction()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
KeyCompFunc CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getKeyCompareFunction

Returns the key compare function used by the map.

Returns
The key compare function.

◆ getEntry() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntry ( const Key &  key)

Returns a mutable iterator pointing to the entry specified by key.

If the map does not contain an entry with the specified key, an iterator pointing one past the last entry of the map (== getEntriesEnd()) is returned.

Parameters
keyThe key specifying the entry.
Returns
A mutable iterator pointing the entry specified by the key or getEntriesEnd(), if the map contains no such entry.

◆ getEntry() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntry ( const Key &  key) const

Returns a constant iterator pointing to the entry specified by key.

If the map does not contain an entry with the specified key, an iterator pointing one past the last entry of the map (== getEntriesEnd()) is returned.

Parameters
keyThe key specifying the entry.
Returns
A constant iterator pointing the entry specified by the key or getEntriesEnd(), if the map contains no such entry.

◆ containsEntry()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
bool CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::containsEntry ( const Key &  key) const

Tells whether the map contains an entry with the specified key.

Parameters
keyThe key specifying the entry.
Returns
true if the map contains the specified entry, and false otherwise.

◆ getValue() [1/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getValue ( const Key &  key)

Returns a non-const reference to the value associated with the specified key.

If the map contains an entry with the specified key, a reference to the associated value is returned. If the map does not contain the entry and default values are enabled (that is, the template parameter AllowDefValues is true), a new map entry is created which associates key with the default constructed value object. Otherwise, Base::ItemNotFound is thrown to indicate the error.

Parameters
keyThe key associated with the requested value.
Returns
A non-const reference to the requested value.
Exceptions
Base::ItemNotFoundif AllowDefValues is false and the map does not contain an entry with the specified key.

◆ getValue() [2/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getValue ( const Key &  key,
Value &  def_value 
)

Returns a non-const reference to the value associated with the specified key, or the value given by the second argument if the specified entry does not exist.

If the map contains an entry with the specified key, a reference to the associated value is returned. If the map does not contain the entry, the second argument def_value is returned.

Parameters
keyThe key associated with the requested value.
def_valueThe value which is returned if the specified entry does not exist.
Returns
A non-const reference to the requested or default value.

◆ getValue() [3/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
const Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getValue ( const Key &  key) const

Returns a const reference to the value associated with the specified key.

If the map contains the specified entry, a reference to the associated value is returned. If the map does not contain the entry and default values are enabled (that is, the template parameter AllowDefValues is true), a const reference to a default constructed value object is returned. Otherwise, Base::ItemNotFound is thrown to indicate the error.

Parameters
keyThe key associated with the requested value.
Returns
A const reference to the requested value.
Exceptions
Base::ItemNotFoundif AllowDefValues is false and the map does not contain an entry with the specified key.

◆ getValue() [4/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
const Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getValue ( const Key &  key,
const Value &  def_value 
) const

Returns a const reference to the value associated with the specified key, or the value given by the second argument if the specified entry does not exist.

If the map contains an entry with the specified key, a reference to the associated value is returned. If the map does not contain the entry, the second argument def_value is returned.

Parameters
keyThe key associated with the requested value.
def_valueThe value which is returned if the specified entry does not exist.
Returns
A const reference to the requested or default value.

◆ operator[]() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::operator[] ( const Key &  key)

Returns a non-const reference to the value associated with the specified key.

The method is equivalent to getValue(const Key&).

Parameters
keyThe key associated with the requested value.
Returns
A non-const reference to the requested value.
Exceptions
Base::ItemNotFoundif AllowDefValues is false and the map does not contain an entry with the specified key.
See also
getValue(const Key&)

◆ operator[]() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
const Value & CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::operator[] ( const Key &  key) const

Returns a const reference to the value associated with the specified key.

The method is equivalent to getValue(const Key&) const.

Parameters
keyThe key associated with the requested value.
Returns
A const reference to the requested value.
Exceptions
Base::ItemNotFoundif AllowDefValues is false and the map does not contain an entry with the specified key.
See also
getValue(const Key&) const

◆ removeEntry() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::removeEntry ( const EntryIterator it)

Removes the entry pointed to by the iterator it from the map.

Parameters
itThe iterator pointing to the entry to remove.

◆ removeEntry() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
bool CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::removeEntry ( const Key &  key)

Removes the entry specified by key from the map.

Parameters
keyThe key specifying the entry to remove.

◆ removeEntries()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::removeEntries ( const EntryIterator first,
const EntryIterator last 
)

Removes all entries pointed to by the iterators in the range [first, last) from the map.

Parameters
firstThe start of the range.
lastThe end of the range.

◆ insertEntry() [1/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
std::pair< typename CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator, bool > CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::insertEntry ( const Entry item)

Tries to insert the key/value pair item into the map.

Inserts item if and only if the map does not already contain an entry whose key is the same as the key of item. The return value is a pair P. P.first is an iterator pointing to the entry whose key is the same as the key of item. P.second is a boolean value which is true if item was actually inserted, and false if the map already contained an entry with the same key as item.

Parameters
itemThe key/value pair to insert.
Returns
A std::pair consisting of an iterator pointing to an entry whose key is the same as the key of item and a boolean value which is true if the insertion of item was successful (an entry with the specified key did not already exist), and false otherwise.

◆ insertEntry() [2/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
std::pair< typename CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator, bool > CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::insertEntry ( const Key &  key,
const Value &  value 
)

Tries to insert a new entry with specified key and value into the map.

Inserts a new entry if and only if the map does not already contain an entry whose key is the same as the specified key. The return value is a pair P. P.first is an iterator pointing to the entry whose key is the same as the specified key. P.second is a boolean value which is true if item was actually inserted, and false if the map already contained an entry with the specified key.

Parameters
keyThe key of the entry to insert.
valueThe value associated with key.
Returns
A std::pair consisting of an iterator pointing to an entry whose key is the same as key and a boolean value, which is true if the insertion of item was successful (an entry with the specified key did not already exist), and false otherwise.

◆ insertEntry() [3/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::insertEntry ( const EntryIterator it,
const Entry item 
)

Tries to insert the key/value pair item into the map and uses the iterator it as a hint for the insertion location.

Inserts item if and only if the map does not already contain an entry whose key is the same as the key of item. The argument it is a hint and points to the location where the insertion position search will begin. The return value is a dereferenceable iterator that points to the entry with a key that is equivalent to that of item.

Parameters
itAn iterator pointing to a location where the insertion position search will begin.
itemThe key/value pair to insert.
Returns
An iterator that points to the entry with a key that is equivalent to that of item.

◆ insertEntry() [4/4]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::insertEntry ( const EntryIterator it,
const Key &  key,
const Value &  value 
)

Tries to insert a new entry with the specified key and value into the map and uses the iterator it as a hint for the insertion location.

Inserts a new entry if and only if the map does not already contain an entry whose key is the same as the specified key. The argument it is a hint and points to the location where the insertion position search will begin. The return value is a dereferenceable iterator that points to the entry with a key that is equivalent to the specified key.

Parameters
itAn iterator pointing to a location where the insertion position search will begin.
keyThe key of the entry to insert.
valueThe value associated with key
Returns
An iterator that points to the entry with a key that is equivalent to the specified key.

◆ setEntry() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::setEntry ( const Entry item)

Inserts a new entry or updates the value of an existing entry with the key and value given by item.

If the map does not already contain an entry whose key is the same as the key of item then a new entry will be created. Otherwise, the value of the existing entry is updated with the value of item. The return value is a dereferenceable iterator that points to the newly inserted or updated entry whose key is equivalent to that of item.

Parameters
itemThe key/value pair.
Returns
An iterator that points to the newly inserted or updated entry.

◆ setEntry() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::setEntry ( const Key &  key,
const Value &  value 
)

Inserts a new entry or updates the value of an existing entry with the specified key and value.

If the map does not already contain an entry whose key is the same as key then a new entry will be created. Otherwise, the value of the existing entry is updated with value. The return value is a dereferenceable iterator that points to the newly inserted or updated entry whose key is equivalent to the specified key.

Parameters
keyThe key of the entry to insert or update.
valueThe value to be associated with key.
Returns
An iterator that points to the newly inserted or updated entry.

◆ insertEntries()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
template<typename InputIter >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::insertEntries ( const InputIter &  first,
const InputIter &  last 
)

Tries to insert the key/value pairs in the range [first, last).

This is equivalent to calling insertEntry(const Entry&) for each key/value pair i that is pointed to by an iterator in the range [first, last). A key/value pair is inserted if and only if the map does not already contain an entry with an equivalent key.

Parameters
firstThe start of the range.
lastThe end of the range.

◆ setEntries()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
template<typename InputIter >
void CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::setEntries ( const InputIter &  first,
const InputIter &  last 
)

Inserts new entries or updates the value of existing entries using the key/value pairs in the range [first, last).

This is equivalent to calling setEntry(const Entry&) for each key/value pair i that is pointed to by an iterator in the range [first, last).

Parameters
firstThe start of the range.
lastThe end of the range.

◆ getLowerBound() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getLowerBound ( const Key &  key)

Returns a mutable iterator pointing to the first entry whose key is not less than the specified key.

Returns
A mutable iterator pointing to the first entry whose key is not less than the specified key.

◆ getLowerBound() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getLowerBound ( const Key &  key) const

Returns a constant iterator pointing to the first entry whose key is not less than the specified key.

Returns
A constant iterator pointing to the first entry whose key is not less than the specified key.

◆ getUpperBound() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getUpperBound ( const Key &  key)

Returns a mutable iterator pointing to the first entry whose key is greater than the specified key.

Returns
A mutable iterator pointing to the first entry whose key is greater than the specified key.

◆ getUpperBound() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getUpperBound ( const Key &  key) const

Returns a constant iterator pointing to the first entry whose key is greater than the specified key.

Returns
A constant iterator pointing to the first entry whose key is greater than the specified key.

◆ getEntriesBegin() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesBegin

Returns a constant iterator pointing to the beginning of the map.

Returns
A constant iterator pointing to the beginning of the map.

◆ getEntriesBegin() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesBegin

Returns a mutable iterator pointing to the beginning of the map.

Returns
A mutable iterator pointing to the beginning of the map.

◆ getEntriesEnd() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesEnd

Returns a constant iterator pointing to the end of the map.

Returns
A constant iterator pointing to the end of the map.

◆ getEntriesEnd() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesEnd

Returns a mutable iterator pointing to the end of the map.

Returns
A mutable iterator pointing to the end of the map.

◆ begin() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::begin

Returns a constant iterator pointing to the beginning of the map.

Returns
A constant iterator pointing to the beginning of the map.

◆ begin() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::begin

Returns a mutable iterator pointing to the beginning of the map.

Returns
A mutable iterator pointing to the beginning of the map.

◆ end() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::end

Returns a constant iterator pointing to the end of the map.

Returns
A constant iterator pointing to the end of the map.

◆ end() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::EntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::end

Returns a mutable iterator pointing to the end of the map.

Returns
A mutable iterator pointing to the end of the map.

◆ getEntriesReverseBegin() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstReverseEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesReverseBegin

Returns a constant iterator pointing to the beginning of the reversed map.

Returns
A constant iterator pointing to the beginning of the reversed map.

◆ getEntriesReverseBegin() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ReverseEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesReverseBegin

Returns a mutable iterator pointing to the beginning of the reversed map.

Returns
A mutable iterator pointing to the beginning of the reversed map.

◆ getEntriesReverseEnd() [1/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ConstReverseEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesReverseEnd

Returns a constant iterator pointing to the end of the reversed map.

Returns
A constant iterator pointing to the end of the reversed map.

◆ getEntriesReverseEnd() [2/2]

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::ReverseEntryIterator CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getEntriesReverseEnd

Returns a mutable iterator pointing to the end of the reversed map.

Returns
A mutable iterator pointing to the end of the reversed map.

◆ getClassName()

template<typename Key , typename Value , bool AllowDefValues, typename KeyCompFunc >
const char * CDPL::Util::Map< Key, Value, AllowDefValues, KeyCompFunc >::getClassName
protectedvirtual

Returns the name of the (derived) Map class.

Overriding this method provides an easy way to customize exception messages with the name of a derived class.

Consider the class MyMap which inherits publicly from Map<int, int> and overrides getClassName():

class MyMap : public CDPL::Util::Map<int, int>
{
.....
private:
const char* getClassName() const {
return "MyMap";
}
};

If, for example, the requested value for a particular key is not found, the error message of the thrown Base::ItemNotFound exception will now start with "MyMap: ...." instead of the default "Map: ....".

Returns
The name of the class as a C-string.
See also
Array::getClassName

The documentation for this class was generated from the following file:
CDPL::Util::Map
A unique sorted associative container that maps keys to values.
Definition: Map.hpp:96
CDPL::Util::Map::getClassName
virtual const char * getClassName() const
Returns the name of the (derived) Map class.
Definition: Map.hpp:1014