|
Chemical Data Processing Library C++ API - Version 1.1.1
|
Go to the documentation of this file.
29 #ifndef CDPL_UTIL_MULTIMAP_HPP
30 #define CDPL_UTIL_MULTIMAP_HPP
48 template <
typename ValueType,
bool Allow = true>
52 static const ValueType&
get()
60 template <
typename ValueType,
bool Allow>
63 template <
typename ValueType>
67 static const ValueType&
get()
93 template <
typename Key,
typename Value,
bool AllowDefValues =
false,
94 typename KeyCompFunc = std::less<Key> >
98 typedef std::multimap<Key, Value, KeyCompFunc> StorageType;
122 typedef typename StorageType::value_type
Entry;
172 template <
typename InputIter>
173 MultiMap(
const InputIter& first,
const InputIter& last):
184 template <
typename InputIter>
185 MultiMap(
const InputIter& first,
const InputIter& last,
const KeyCompFunc& func):
186 data(first, last, func)
347 const Value&
getValue(
const Key& key,
const Value& def_value)
const;
478 template <
typename InputIter>
491 template <
typename InputIter>
492 void setEntries(
const InputIter& first,
const InputIter& last);
621 const Value& getDefaultValue()
const;
634 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
646 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
658 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
670 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
682 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
694 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
704 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
705 typename CDPL::Util::MultiMap<Key, Value, AllowDefValues, KeyCompFunc>::StorageType&
711 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
712 const typename CDPL::Util::MultiMap<Key, Value, AllowDefValues, KeyCompFunc>::StorageType&
718 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
724 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
730 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
736 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
742 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
745 return data.key_comp();
748 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
751 return data.count(key);
754 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
758 return data.find(key);
761 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
765 return data.find(key);
768 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
772 return data.equal_range(key);
775 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
779 return data.equal_range(key);
782 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
787 if (lb == data.end() || data.key_comp()(key, (*lb).first)) {
791 return (*data.insert(lb,
Entry(key, getDefaultValue()))).second;
797 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
802 if (it == data.end())
808 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
813 if (it == data.end()) {
817 return getDefaultValue();
823 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
825 const Value& def_value)
const
829 if (it == data.end())
835 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
838 return getValue(key);
841 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
844 return getValue(key);
847 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
853 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
858 if (it == data.end())
865 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
868 return data.erase(key);
871 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
875 data.erase(first, last);
878 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
882 return data.insert(item);
885 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
889 return data.insert(
Entry(key, value));
892 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
896 return data.insert(it, item);
899 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
904 return data.insert(it,
Entry(key, value));
907 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
914 if (lb == end || data.key_comp()(item.first, (*lb).first))
915 return data.insert(lb, item);
919 while (range_end != end && !data.key_comp()(item.first, (*range_end).first))
922 data.erase(lb, range_end);
924 return data.insert(range_end, item);
927 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
931 return setEntry(
Entry(key, value));
934 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
935 template <
typename InputIter>
937 const InputIter& last)
939 data.insert(first, last);
942 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
943 template <
typename InputIter>
945 const InputIter& last)
947 for (InputIter it = first; it != last; ++it)
951 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
955 return data.lower_bound(key);
958 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
962 return data.lower_bound(key);
965 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
969 return data.upper_bound(key);
972 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
976 return data.upper_bound(key);
979 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
986 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
993 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1000 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1007 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1011 return data.begin();
1014 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1018 return data.begin();
1021 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1028 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1035 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1039 return data.rbegin();
1042 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1046 return data.rbegin();
1049 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1056 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1063 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1069 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1077 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1079 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1081 return (map1.getData() == map2.getData());
1084 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1086 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1088 return (map1.getData() != map2.getData());
1091 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1093 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1095 return (map1.getData() <= map2.getData());
1098 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1100 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1102 return (map1.getData() >= map2.getData());
1105 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1107 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1109 return (map1.getData() < map2.getData());
1112 template <
typename Key,
typename Value,
bool AllowDefValues,
typename KeyCompFunc>
1114 const MultiMap<Key, Value, AllowDefValues, KeyCompFunc>& map2)
1116 return (map1.getData() > map2.getData());
1121 #endif // CDPL_UTIL_MULTIMAP_HPP
StorageType::const_iterator ConstEntryIterator
A constant iterator used to iterate over the entries of the map.
Definition: MultiMap.hpp:127
EntryIterator insertEntry(const EntryIterator &it, const Key &key, const Value &value)
Inserts a new entry with the specified key and value into the map and uses the iterator it as a hint ...
Definition: MultiMap.hpp:901
std::pair< EntryIterator, EntryIterator > EntryIteratorRange
A pair of mutable iterators used to specify the start and end of a range of entries.
Definition: MultiMap.hpp:147
Definition: MultiMap.hpp:50
void removeEntry(const EntryIterator &it)
Removes the entry pointed to by the iterator it from the map.
Definition: MultiMap.hpp:848
bool isEmpty() const
Tells whether the map is empty (getSize() == 0).
Definition: MultiMap.hpp:725
ConstEntryIterator getUpperBound(const Key &key) const
Returns a constant iterator pointing to the first entry whose key is greater than the specified key.
Definition: MultiMap.hpp:974
EntryIterator setEntry(const Key &key, const Value &value)
Replaces all entries with a key equivalent to key with a single copy of the key/value pair (key,...
Definition: MultiMap.hpp:929
const StorageType & getData() const
Definition: MultiMap.hpp:713
EntryIterator getUpperBound(const Key &key)
Returns a mutable iterator pointing to the first entry whose key is greater than the specified key.
Definition: MultiMap.hpp:967
MultiMap(const InputIter &first, const InputIter &last)
Creates and initializes the map with copies of the key value pairs in the range [first,...
Definition: MultiMap.hpp:173
bool operator!=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Inequality comparison operator.
ConstEntryIterator getEntry(const Key &key) const
Returns a constant iterator pointing to the first entry with the specified key.
Definition: MultiMap.hpp:763
ReverseEntryIterator getEntriesReverseBegin()
Returns a mutable iterator pointing to the beginning of the reversed map.
Definition: MultiMap.hpp:1044
StorageType::reverse_iterator ReverseEntryIterator
A mutable iterator used to iterate backwards over the entries of the map.
Definition: MultiMap.hpp:142
static const ValueType & get()
Definition: MultiMap.hpp:52
EntryIterator insertEntry(const EntryIterator &it, const Entry &item)
Inserts the key/value pair item into the map and uses the iterator it as a hint for the insertion loc...
Definition: MultiMap.hpp:894
Thrown to indicate that some requested operation has failed (e.g. due to unfulfilled preconditions or...
Definition: Base/Exceptions.hpp:211
Thrown to indicate that some requested data item could not be found.
Definition: Base/Exceptions.hpp:171
std::pair< ConstEntryIterator, ConstEntryIterator > ConstEntryIteratorRange
A pair of constant iterators used to specify the start and end of a range of entries.
Definition: MultiMap.hpp:152
std::size_t getNumEntries(const Key &key) const
Returns the number of entries with the specified key.
Definition: MultiMap.hpp:749
virtual const char * getClassName() const
Returns the name of the (derived) Map class.
Definition: MultiMap.hpp:1064
StorageType::const_reverse_iterator ConstReverseEntryIterator
A constant iterator used to iterate backwards over the entries of the map.
Definition: MultiMap.hpp:132
StorageType::value_type Entry
The type of the key/value pairs stored in the map.
Definition: MultiMap.hpp:122
void clear()
Erases all entries.
Definition: MultiMap.hpp:731
EntryIterator end()
Returns a mutable iterator pointing to the end of the map.
Definition: MultiMap.hpp:1030
EntryIterator getLowerBound(const Key &key)
Returns a mutable iterator pointing to the first entry whose key is not less than the specified key.
Definition: MultiMap.hpp:953
EntryIterator insertEntry(const Entry &item)
Inserts the key/value pair item into the map.
Definition: MultiMap.hpp:880
Value ValueType
The type of the mapped values.
Definition: MultiMap.hpp:114
EntryIterator getEntriesBegin()
Returns a mutable iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:988
ConstEntryIterator getEntriesBegin() const
Returns a constant iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:981
const Value & getValue(const Key &key, const Value &def_value) const
Returns a const reference to the first value associated with the specified key, or the value given by...
Definition: MultiMap.hpp:824
ConstReverseEntryIterator getEntriesReverseEnd() const
Returns a constant iterator pointing to the end of the reversed map.
Definition: MultiMap.hpp:1051
EntryIterator getEntriesEnd()
Returns a mutable iterator pointing to the end of the map.
Definition: MultiMap.hpp:1002
EntryIteratorRange getEntries(const Key &key)
Returns the bounds of a range that includes all entries with a key that compares equal to the specifi...
Definition: MultiMap.hpp:770
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 [...
Definition: MultiMap.hpp:944
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
bool operator>=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater or equal comparison operator.
ConstReverseEntryIterator getEntriesReverseBegin() const
Returns a constant iterator pointing to the beginning of the reversed map.
Definition: MultiMap.hpp:1037
ReverseEntryIterator getEntriesReverseEnd()
Returns a mutable iterator pointing to the end of the reversed map.
Definition: MultiMap.hpp:1058
ConstEntryIterator begin() const
Returns a constant iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:1009
bool removeEntry(const Key &key)
Removes the first entry with the specified key from the map.
Definition: MultiMap.hpp:854
Value & getValue(const Key &key, Value &def_value)
Returns a non-const reference to the first value associated with the specified key,...
Definition: MultiMap.hpp:798
StorageType::iterator EntryIterator
A mutable iterator used to iterate over the entries of the map.
Definition: MultiMap.hpp:137
A multiple sorted associative container that maps keys to values.
Definition: MultiMap.hpp:96
virtual ~MultiMap()
Virtual destructor.
Definition: MultiMap.hpp:192
void insertEntries(const InputIter &first, const InputIter &last)
Inserts the key/value pairs in the range [first, last) into the map.
Definition: MultiMap.hpp:936
Definition of exception classes.
bool operator<=(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less or equal comparison operator.
MultiMap(const KeyCompFunc &func)
Creates an empty map and uses func as key compare function.
Definition: MultiMap.hpp:164
Value & operator[](const Key &key)
Returns a non-const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:836
The namespace of the Chemical Data Processing Library.
StorageType & getData()
Definition: MultiMap.hpp:706
EntryIterator getEntry(const Key &key)
Returns a mutable iterator pointing to the first entry with the specified key.
Definition: MultiMap.hpp:756
static const ValueType defValue
Definition: MultiMap.hpp:57
KeyCompFunc getKeyCompareFunction() const
Returns the key compare function used by the map.
Definition: MultiMap.hpp:743
Key KeyType
The type of the map's keys.
Definition: MultiMap.hpp:109
ConstEntryIterator getLowerBound(const Key &key) const
Returns a constant iterator pointing to the first entry whose key is not less than the specified key.
Definition: MultiMap.hpp:960
const Value & operator[](const Key &key) const
Returns a const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:842
EntryIterator insertEntry(const Key &key, const Value &value)
Inserts a new entry with specified key and value into the map.
Definition: MultiMap.hpp:887
const Value & getValue(const Key &key) const
Returns a const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:809
void removeEntries(const EntryIterator &first, const EntryIterator &last)
Removes all entries pointed to by the iterators in the range [first, last) from the map.
Definition: MultiMap.hpp:872
Value & getValue(const Key &key)
Returns a non-const reference to the first value associated with the specified key.
Definition: MultiMap.hpp:783
ConstEntryIterator end() const
Returns a constant iterator pointing to the end of the map.
Definition: MultiMap.hpp:1023
static const ValueType & get()
Definition: MultiMap.hpp:67
bool operator>(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater than comparison operator.
MultiMap()
Creates an empty map.
Definition: MultiMap.hpp:157
ConstEntryIterator getEntriesEnd() const
Returns a constant iterator pointing to the end of the map.
Definition: MultiMap.hpp:995
EntryIterator setEntry(const Entry &item)
Replaces all entries with a key equivalent to that of item with a single entry specified by item.
Definition: MultiMap.hpp:909
bool operator==(const Array< ValueType > &array1, const Array< ValueType > &array2)
Equality comparison operator.
std::size_t getSize() const
Returns the size (number of entries) of the map.
Definition: MultiMap.hpp:719
std::size_t removeEntries(const Key &key)
Removes all entries with the specified key from the map.
Definition: MultiMap.hpp:866
MultiMap(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,...
Definition: MultiMap.hpp:185
std::shared_ptr< MultiMap > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MultiMap instances.
Definition: MultiMap.hpp:104
EntryIterator begin()
Returns a mutable iterator pointing to the beginning of the map.
Definition: MultiMap.hpp:1016
void swap(MultiMap &map)
Swaps the contents with map.
Definition: MultiMap.hpp:737
ConstEntryIteratorRange getEntries(const Key &key) const
Returns the bounds of a range that includes all entries with a key that compares equal to the specifi...
Definition: MultiMap.hpp:777