Introduce Map.key_type and Map.value_type
authorDidier 'Ptitjes <ptitjes@free.fr>
Wed, 23 Sep 2009 22:51:55 +0000 (00:51 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Wed, 23 Sep 2009 22:51:55 +0000 (00:51 +0200)
gee/abstractmap.vala
gee/map.vala
gee/readonlymap.vala
tests/testmap.vala

index e798876..8e7ab9f 100644 (file)
@@ -179,6 +179,20 @@ public abstract class Gee.AbstractMap<K,V> : Object, Iterable<Map.Entry<K,V>>, M
        /**
         * @inheritDoc
         */
+       public Type key_type {
+               get { return typeof (K); }
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public Type value_type {
+               get { return typeof (V); }
+       }
+
+       /**
+        * @inheritDoc
+        */
        public Type element_type {
                get { return typeof (Map.Entry<K,V>); }
        }
index f085c5f..917cff3 100644 (file)
@@ -190,6 +190,16 @@ public interface Gee.Map<K,V> : GLib.Object, Iterable<Map.Entry<K,V>> {
        public abstract Map<K,V> read_only_view { owned get; }
 
        /**
+        * The type of the keys in this map.
+        */
+       public abstract Type key_type { get; }
+
+       /**
+        * The type of the values in this map.
+        */
+       public abstract Type value_type { get; }
+
+       /**
         * Returns an immutable empty map.
         *
         * @return an immutable empty map
index d89ba1e..3bf164b 100644 (file)
@@ -190,6 +190,20 @@ internal class Gee.ReadOnlyMap<K,V> : Object, Iterable<Map.Entry<K,V>>, Map<K,V>
        /**
         * @inheritDoc
         */
+       public Type key_type {
+               get { return typeof (K); }
+       }
+
+       /**
+        * @inheritDoc
+        */
+       public Type value_type {
+               get { return typeof (V); }
+       }
+
+       /**
+        * @inheritDoc
+        */
        public Type element_type {
                get { return typeof (Map.Entry<K,V>); }
        }
index 3254482..e416263 100644 (file)
@@ -29,6 +29,7 @@ public abstract class MapTests : Gee.TestCase {
 
        public MapTests (string name) {
                base (name);
+               add_test ("[Map] type correctness", test_type_correctness);
                add_test ("[Map] has_key, size and is_empty",
                          test_has_key_size_is_empty);
                add_test ("[Map] keys", test_keys);
@@ -41,6 +42,15 @@ public abstract class MapTests : Gee.TestCase {
 
        protected Map<string, string> test_map;
 
+       public void test_type_correctness () {
+               // Check the map exists
+               assert (test_map != null);
+
+               // Check the advertised key and value types
+               assert (test_map.key_type == typeof (string));
+               assert (test_map.value_type == typeof (string));
+       }
+
        public void test_has_key_size_is_empty () {
                // Check the collection exists
                assert (test_map != null);