diff options
author | Alexis211 <alexis211@gmail.com> | 2009-12-22 15:01:07 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-12-22 15:01:07 +0100 |
commit | 98decfffefc49c82f20a0453cef823f7588e7654 (patch) | |
tree | cf0b4c5b0fb491adc66a6f74d51f6a853614932c /Source/Library/Common/Map.class.cpp | |
parent | 18454dc8be12827a84c2ebc58aa5d31bb44e1e6a (diff) | |
download | Melon-98decfffefc49c82f20a0453cef823f7588e7654.tar.gz Melon-98decfffefc49c82f20a0453cef823f7588e7654.zip |
Added template class Map<key, value>
Diffstat (limited to 'Source/Library/Common/Map.class.cpp')
-rw-r--r-- | Source/Library/Common/Map.class.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/Library/Common/Map.class.cpp b/Source/Library/Common/Map.class.cpp new file mode 100644 index 0000000..d9a4e39 --- /dev/null +++ b/Source/Library/Common/Map.class.cpp @@ -0,0 +1,38 @@ +template <typename K, typename V> +Map<K, V>::Map() { + m_root = 0; +} + +template <typename K, typename V> +Map<K, V>::~Map() { + if (m_root != 0) delete m_root; +} + +template <typename K, typename V> +bool Map<K, V>::has(const K& key) { + return (find(key, m_root) != 0); +} + +template <typename K, typename V> +void Map<K, V>::set(const K& key, const V& value) { + item_t* i = find(key, m_root); + if (i == 0) m_root = insert(key, value, m_root); + else i->value = value; +} + +template <typename K, typename V> +const V& Map<K, V>::get(const K& key) { + item_t* i = find(key); + if (i == 0) return m_null; + return i->value; +} + +template <typename K, typename V> +V& Map<K, V>::operator[] (const K& key) { + item_t* i = find(key, m_root); + if (i == 0) { + m_root = insert(key, m_null, m_root); + i = find(key, m_root); + } + return i->value; +} |