summaryrefslogtreecommitdiff
path: root/Source/Library/Common/Map.class.cpp
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-12-22 19:52:39 +0100
committerAlexis211 <alexis211@gmail.com>2009-12-22 19:52:39 +0100
commit7ede286ebcb845fe4bfdfb948c6073573b01c3cb (patch)
tree38a20fecb9e1ede89d2f3f7c7c9354eb700ddaa5 /Source/Library/Common/Map.class.cpp
parenta7e116c4b2378f65a0a531f9b2a2102d4a80f524 (diff)
parentcc1193087067c7e1105bd3d788520c034f5cf619 (diff)
downloadMelon-7ede286ebcb845fe4bfdfb948c6073573b01c3cb.tar.gz
Melon-7ede286ebcb845fe4bfdfb948c6073573b01c3cb.zip
Merge branch 'master' of github.com:Alexis211/Melon
Conflicts: Melon.img
Diffstat (limited to 'Source/Library/Common/Map.class.cpp')
-rw-r--r--Source/Library/Common/Map.class.cpp38
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;
+}