45#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_DICTIONARY_INL
46#define LASS_GUARDIAN_OF_INCLUSION_UTIL_DICTIONARY_INL
58template <
typename K,
typename V,
typename KL,
typename VL>
59Dictionary<K, V, KL, VL>::Dictionary():
62 enableSuggestions_(false)
68template <
typename K,
typename V,
typename KL,
typename VL>
69Dictionary<K, V, KL, VL>::Dictionary(TKeyLess iKeyLess):
73 enableSuggestions_(false)
79template <
typename K,
typename V,
typename KL,
typename VL>
80Dictionary<K, V, KL, VL>::Dictionary(TKeyLess iKeyLess, TValueLess iValueLess):
83 valueLess_(iValueLess),
85 enableSuggestions_(false)
93template <
typename K,
typename V,
typename KL,
typename VL>
96 std::pair<typename TMap::iterator, typename TMap::iterator> range = map_.equal_range(iKey);
97 for (
typename TMap::iterator i = range.first; i != range.second; ++i)
99 if (equalValues(i->second, iValue))
104 map_.insert(
typename TMap::value_type(iKey, iValue));
111template <
typename K,
typename V,
typename KL,
typename VL>
114 std::pair<typename TMap::iterator, typename TMap::iterator> range = map_.equal_range(iKey);
115 for (
typename TMap::iterator i = range.first; i != range.second; ++i)
117 if (equalValues(i->second, iValue))
131template <
typename K,
typename V,
typename KL,
typename VL>
135 defaultValue_ = iValue;
145template <
typename K,
typename V,
typename KL,
typename VL>
155template <
typename K,
typename V,
typename KL,
typename VL>
166template <
typename K,
typename V,
typename KL,
typename VL>
169 enableSuggestions_ = enable;
186template <
typename K,
typename V,
typename KL,
typename VL>
187const typename Dictionary<K, V, KL, VL>::TValue&
190 typename TMap::const_iterator i = map_.find(iKey);
195 if (enableSuggestions_)
197 LASS_THROW(
"Key '" << iKey <<
"' is not found in dictionary, please try one "
198 <<
"of these: " <<
keys());
202 LASS_THROW(
"Key '" << iKey <<
"' is not found in dictionary.");
205 return defaultValue_;
223template <
typename K,
typename V,
typename KL,
typename VL>
224const typename Dictionary<K, V, KL, VL>::TKey&
227 for (
typename TMap::const_iterator i = map_.begin(); i != map_.end(); ++i)
229 if (equalValues(i->second, iValue))
236 if (enableSuggestions_)
238 LASS_THROW(
"Value '" << iValue <<
"' is not found in dictionary, please try one "
239 <<
"of these: " <<
values());
243 LASS_THROW(
"Value '" << iValue <<
"' is not found in dictionary.");
253template <
typename K,
typename V,
typename KL,
typename VL>
254typename Dictionary<K, V, KL, VL>::TKeys
258 for (
typename TMap::const_iterator i = map_.begin(); i != map_.end(); ++i)
260 result.insert(i->first);
269template <
typename K,
typename V,
typename KL,
typename VL>
270typename Dictionary<K, V, KL, VL>::TValues
274 for (
typename TMap::const_iterator i = map_.begin(); i != map_.end(); ++i)
276 result.insert(i->second);
285template <
typename K,
typename V,
typename KL,
typename VL>
286typename Dictionary<K, V, KL, VL>::TKeys
290 for (
typename TMap::const_iterator i = map_.begin(); i != map_.end(); ++i)
292 if (equalValues(i->second, iValue))
294 result.insert(i->first);
304template <
typename K,
typename V,
typename KL,
typename VL>
305typename Dictionary<K, V, KL, VL>::TValues
309 std::pair<typename TMap::const_iterator, typename TMap::const_iterator> range = map_.equal_range(iKey);
310 for (
typename TMap::const_iterator i = range.first; i != range.second; ++i)
312 result.insert(i->second);
321template <
typename K,
typename V,
typename KL,
typename VL>
324 return map_.find(iKey) != map_.end();
331template <
typename K,
typename V,
typename KL,
typename VL>
334 for (
typename TMap::const_iterator i = map_.begin(); i != map_.end(); ++i)
336 if (equalValues(i->second, iValue))
352template <
typename K,
typename V,
typename KL,
typename VL>
353bool Dictionary<K, V, KL, VL>::equalValues(TValueParam iA, TValueParam iB)
const
355 return !valueLess_(iA, iB) && !valueLess_(iB, iA);
void remove(const TKey &iKey, const TValue &iValue)
remove a key and value from the dictionary.
bool hasDefault() const
return true if dictionary has value
void setDefault(const TKey &iKey, const TValue &iValue)
set key and value to be used as default ones.
bool isValue(TValueParam iValue) const
return true if iValue is a value of dictionary
void clearDefault()
clear default key and value.
const TKey & key(TValueParam iValue) const
look up a key by value
void add(const TKey &iKey, const TValue &iValue)
add a key and value to dictionary as new entry.
TValues values() const
return all values in the dictionary
const TValue & operator[](TKeyParam iKey) const
look up a value by key
void enableSuggestions(bool enable=true)
if enabled, suggestions of valid keys or values will be included in the exception that is thrown in c...
bool isKey(TKeyParam iKey) const
return true if iKey is a key of dictionary
TKeys keys() const
return all keys in the dictionary
general utility, debug facilities, ...
Library for Assembled Shared Sources.