5 #ifndef BALL_DATATYPE_HASHMAP_H 6 #define BALL_DATATYPE_HASHMAP_H 8 #ifndef BALL_COMMON_EXCEPTION_H 12 #ifndef BALL_DATATYPE_STRING_H 16 #ifndef BALL_DATATYPE_TRIPLE_H 20 #ifndef BALL_DATATYPE_QUADRUPLE_H 24 #include <boost/unordered_map.hpp> 25 #include <boost/functional/hash.hpp> 32 size_t operator () (
const BALL::String& s)
const {
return boost::hash<std::string>()(s); }
35 template <
typename T1,
typename T2,
typename T3>
36 struct hash<
BALL::Triple<T1, T2, T3> >
41 boost::hash_combine(hash, s.
first);
42 boost::hash_combine(hash, s.
second);
43 boost::hash_combine(hash, s.
third);
49 template <
typename T1,
typename T2,
typename T3,
typename T4>
50 struct hash<
BALL::Quadruple<T1, T2, T3, T4> >
55 boost::hash_combine(hash, s.
first);
56 boost::hash_combine(hash, s.
second);
57 boost::hash_combine(hash, s.
third);
58 boost::hash_combine(hash, s.
fourth);
72 template <
class Key,
class T>
73 class HashMap :
public boost::unordered_map<Key, T>
86 : Exception::GeneralException(file, line)
93 typedef boost::unordered_map<Key, T>
Base;
102 inline bool has(
const Key& key)
const 104 return Base::find(key) != Base::end();
112 const T& operator [] (
const Key& key)
const;
115 T& operator [] (
const Key& key);
129 template <
class Key,
class T>
133 if (it == Base::end())
135 throw IllegalKey(__FILE__, __LINE__);
143 template <
class Key,
class T>
147 if (Base::size() != rhs.
size())
156 for (; it != Base::end(); ++it)
158 if (!rhs.
has(it->first))
return false;
164 template <
class Key,
class T>
167 return Base::operator[] (key);
172 #endif // BALL_DATATYPE_HASHMAP_H
Base::const_iterator ConstIterator
IllegalKey(const char *file, int line)
bool has(const Key &key) const
Test whether the map contains the given key.
boost::unordered_map< Key, T > Base
Base::value_type * PointerType
BALL_EXPORT bool operator==(const String &s1, const String &s2)
HashMap illegal key exception.
-*- Mode: C++; tab-width: 2; -*-
Base::value_type ValueType
HashMap class based on the STL map (containing serveral convenience functions)