![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #ifndef __DICTIONARY_H 00002 #define __DICTIONARY_H 00003 00004 #include "CodeGenMacros.h" 00005 #include <map> 00006 00010 template<class Key, class Value> 00011 class Dictionary : public std::map<Key, Value> 00012 { 00013 protected: 00014 Value _defaultValue; 00015 00016 public: 00017 INLINE GET(getDefaultValue, Value, _defaultValue) 00018 INLINE SET(setDefaultValue, Value, _defaultValue) 00019 00024 INLINE Value getSafe(Key id) const 00025 { 00026 std::map<Key, Value>::const_iterator iter = find(id); 00027 if(iter == end()) 00028 return _defaultValue; 00029 else 00030 return iter->second; 00031 } 00032 00036 INLINE bool has(Key id) const 00037 { 00038 std::map<Key, Value>::const_iterator iter = find(id); 00039 if(iter == end()) 00040 return false; 00041 else 00042 return true; 00043 } 00044 00049 INLINE void remove(Key id) 00050 { 00051 std::map<Key, Value>::iterator iter = find(id); 00052 if(iter != end()) 00053 erase(iter); 00054 } 00055 }; 00056 00057 00058 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.