/* ** boost-hash.h ** ** This file is part of mkxp. ** ** Copyright (C) 2013 Jonas Kulla ** ** mkxp is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 2 of the License, or ** (at your option) any later version. ** ** mkxp is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with mkxp. If not, see . */ #ifndef BOOSTHASH_H #define BOOSTHASH_H #include #include #include #include /* Wrappers around the boost unordered template classes, * exposing an interface similar to Qt's QHash/QSet */ template class BoostHash { private: typedef std::map BoostType; typedef std::pair PairType; BoostType p; public: typedef typename BoostType::const_iterator const_iterator; inline bool contains(const K &key) const { const_iterator iter = p.find(key); return (iter != p.cend()); } inline void insert(const K &key, const V &value) { p.insert(PairType(key, value)); } inline void remove(const K &key) { p.erase(key); } inline const V value(const K &key) const { const_iterator iter = p.find(key); if (iter == p.cend()) return V(); return iter->second; } inline const V value(const K &key, const V &defaultValue) const { const_iterator iter = p.find(key); if (iter == p.cend()) return defaultValue; return iter->second; } inline V &operator[](const K &key) { return p[key]; } inline const_iterator cbegin() const { return p.cbegin(); } inline const_iterator cend() const { return p.cend(); } }; template class BoostSet { private: typedef std::set BoostType; BoostType p; public: typedef typename BoostType::const_iterator const_iterator; inline bool contains(const K &key) { const_iterator iter = p.find(key); return (iter != p.cend()); } inline void insert(const K &key) { p.insert(key); } inline void remove(const K &key) { p.erase(key); } inline const_iterator cbegin() const { return p.cbegin(); } inline const_iterator cend() const { return p.cend(); } }; #endif // BOOSTHASH_H