![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #ifndef __MANAGEDDICTIONARY_H 00002 #define __MANAGEDDICTIONARY_H 00003 00004 #include "Dictionary.h" 00005 00016 template <class Key, class Value> 00017 class ManagedDictionary : public Dictionary<Key, Value*> 00018 { 00019 protected: 00020 bool _manageMemory; 00021 00022 public: 00026 ManagedDictionary() : _manageMemory(false) 00027 { 00028 setDefaultValue(NULL); 00029 } 00030 00035 ManagedDictionary(bool manageMemory) : _manageMemory(manageMemory) 00036 { 00037 setDefaultValue(NULL); 00038 } 00039 00044 ManagedDictionary(bool manageMemory, Value* defaultValue) : _manageMemory(manageMemory) 00045 { 00046 setDefaultValue(defaultValue); 00047 } 00048 00053 ~ManagedDictionary() 00054 { 00055 //if we are not managing memory, then abort 00056 if(!_manageMemory) 00057 return; 00058 00059 //if we are managing memory, then delete all objects in the map 00060 std::map<Key, Value*>::const_iterator iter = begin(); 00061 while(iter != end()) 00062 { 00063 delete (iter->second); 00064 ++iter; 00065 } 00066 } 00067 00068 //If "managed" is true then delete values in destructor, else do nothing 00069 INLINE GET(getManaged, bool, _manageMemory) 00070 INLINE SET(setManaged, bool, _manageMemory) 00071 }; 00072 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.