X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fmaputils.h;h=66b4e3baf82c50d815f5bcf4ce0615729ebbf0fb;hb=7be37ad97a2fd3494cb5d56badb45997353ff709;hp=0f863b46fdf7dea307f251be4823a4e63cdcbc4e;hpb=676f6faa92d23c2096a6a85cac819925dbdc1a88;p=libs%2Fcore.git diff --git a/source/core/maputils.h b/source/core/maputils.h index 0f863b4..66b4e3b 100644 --- a/source/core/maputils.h +++ b/source/core/maputils.h @@ -74,8 +74,14 @@ const typename T::mapped_type &get_item(const T &map, const typename T::key_type return i->second; } +template +D *get_item(const T &map, const typename T::key_type &key) +{ + return dynamic_cast(get_item(map, key)); +} + template -const typename T::iterator insert_unique(T &map, const typename T::key_type &key, const typename T::mapped_type &item) +typename T::iterator insert_unique(T &map, const typename T::key_type &key, const typename T::mapped_type &item) { if(map.count(key)) throw key_error(key); @@ -83,6 +89,15 @@ const typename T::iterator insert_unique(T &map, const typename T::key_type &key return map.insert(typename T::value_type(key, item)).first; } +template +void remove_existing(T &map, const typename T::key_type &key) +{ + if(!map.count(key)) + throw key_error(key); + + map.erase(key); +} + } // namespace Msp #endif