Add *_type property for all collections, fixes bug #663337
authorMaciej Piechotka <uzytkownik2@gmail.com>
Mon, 19 Dec 2011 16:58:29 +0000 (17:58 +0100)
committerMaciej Piechotka <uzytkownik2@gmail.com>
Mon, 19 Dec 2011 17:05:43 +0000 (18:05 +0100)
15 files changed:
gee/abstractmultimap.vala
gee/abstractmultiset.vala
gee/arraylist.vala
gee/concurrentlist.vala
gee/hashmap.vala
gee/hashset.vala
gee/linkedlist.vala
gee/multimap.vala
gee/priorityqueue.vala
gee/readonlycollection.vala
gee/traversable.vala
gee/treemap.vala
gee/treeset.vala
gee/unfolditerator.vala
tests/testmultimap.vala

index ed547eb..61f8a01 100644 (file)
@@ -130,4 +130,8 @@ public abstract class Gee.AbstractMultiMap<K,V> : Object, MultiMap<K,V> {
                _storage_map.clear ();
                _nitems = 0;
        }
+
+       public Type key_type { get { return typeof(K); } }
+
+       public Type value_type { get { return typeof(V); } }
 }
index fc9fe7d..147fb7e 100644 (file)
@@ -162,6 +162,10 @@ public abstract class Gee.AbstractMultiSet<G> : AbstractCollection<G>, MultiSet<
                        _removed = false;
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public Gee.Iterator<A> stream<A> (owned StreamFunc<A, G> f) {
                        return Gee.Iterator.stream_impl<G, A>(this, (owned)f);
                }
index a051378..3f7018e 100644 (file)
@@ -388,6 +388,10 @@ public class Gee.ArrayList<G> : AbstractBidirList<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        assert (_stamp == _list._stamp);
                        if (_index < 0 || _removed)
index 91bfa22..356157d 100644 (file)
@@ -338,6 +338,10 @@ public class Gee.ConcurrentList<G> : AbstractList<G> {
                        _index++;
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public new void foreach (ForallFunc<G> f) {
                        HazardPointer.Context ctx = new HazardPointer.Context ();
                        if (_started && !_removed)
index 57f1412..d71d964 100644 (file)
@@ -539,6 +539,10 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
                        assert_not_reached ();
                }
 
+               public Type element_type {
+                       get { return typeof (K); }
+               }
+
                public void foreach(ForallFunc<K> f) {
                        if (_node != null) {
                                f(_node.key);
@@ -632,6 +636,10 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
                        assert_not_reached ();
                }
 
+               public Type element_type {
+                       get { return typeof (V); }
+               }
+
                public void foreach(ForallFunc<V> f) {
                        if (_node != null) {
                                f(_node.value);
@@ -679,6 +687,10 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
                        assert_not_reached ();
                }
 
+               public Type element_type {
+                       get { return typeof (Entry<K, V>); }
+               }
+
                public void foreach(ForallFunc<Map.Entry<K,V>> f) {
                        if (_node != null) {
                                f(Entry<K,V>.entry_for<K,V> (_node));
index 85152f5..3e8ae01 100644 (file)
@@ -279,6 +279,10 @@ public class Gee.HashSet<G> : AbstractSet<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        assert (_stamp == _set._stamp);
                        if (_node != null)
index fb8fae5..575c63b 100644 (file)
@@ -605,6 +605,10 @@ public class Gee.LinkedList<G> : AbstractBidirList<G>, Queue<G>, Deque<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        assert (_stamp == _list._stamp);
                        if (!started) {
index 373ac08..8069c8e 100644 (file)
@@ -106,4 +106,14 @@ public interface Gee.MultiMap<K,V> : Object {
         * Removes all items from this collection.
         */
        public abstract void clear ();
+
+       /**
+        * The type of the keys in this multimap.
+        */
+       public abstract Type key_type { get; }
+
+       /**
+        * The type of the values in this multimap.
+        */
+       public abstract Type value_type { get; }
 }
index b1a07ad..e40676b 100644 (file)
@@ -1035,6 +1035,10 @@ public class Gee.PriorityQueue<G> : Gee.AbstractQueue<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        if (valid)
                                f (position.data);
index df5d986..fcf76f4 100644 (file)
@@ -193,19 +193,23 @@ internal class Gee.ReadOnlyCollection<G> : Object, Traversable<G>, Iterable<G>,
                public void remove () {
                        assert_not_reached ();
                }
-               
+
                public bool valid {
                        get {
                                return _iter.valid;
                        }
                }
-               
+
                public bool read_only {
                        get {
                                return true;
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        _iter.foreach (f);
                }
index 9af35eb..c8219c2 100644 (file)
@@ -51,8 +51,7 @@ namespace Gee {
  *
  * @since 0.7.0
  */
-public interface Gee.Traversable<G> : Object
-{      
+public interface Gee.Traversable<G> : Object {
        /**
         * Apply function to each element returned by iterator. 
         *
index 02587c6..2b8d05b 100644 (file)
@@ -1645,6 +1645,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        return current.key;
                }
 
+               public Type element_type {
+                       get { return typeof (K); }
+               }
+
                public void foreach (ForallFunc<K> f) {
                        if (current != null) {
                                f (current.key);
@@ -1690,6 +1694,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        return iterator.current.key;
                }
 
+               public Type element_type {
+                       get { return typeof (K); }
+               }
+
                public void foreach (ForallFunc<K> f) {
                        if (valid)
                                f (iterator.current.key);
@@ -1725,6 +1733,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        return current.value;
                }
 
+               public Type element_type {
+                       get { return typeof (V); }
+               }
+
                public void foreach (ForallFunc<V> f) {
                        if (current != null) {
                                f (current.key);
@@ -1770,6 +1782,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        return iterator.current.value;
                }
 
+               public Type element_type {
+                       get { return typeof (V); }
+               }
+
                public void foreach (ForallFunc<V> f) {
                        if (valid)
                                f (iterator.current.key);
@@ -1809,6 +1825,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        unset ();
                }
 
+               public Type element_type {
+                       get { return typeof (Entry<K, V>); }
+               }
+
                public void foreach (ForallFunc<Map.Entry<K, V>> f) {
                        if (current != null) {
                                f (Entry.entry_for<K,V> (current));
@@ -1858,6 +1878,10 @@ public class Gee.TreeMap<K,V> : Gee.AbstractSortedMap<K,V> {
                        unset ();
                }
 
+               public Type element_type {
+                       get { return typeof (Entry<K, V>); }
+               }
+
                public void foreach (ForallFunc<Map.Entry<K, V>> f) {
                        if (valid)
                                f (Entry.entry_for<K,V> (iterator.current));
index 6bcc0a5..342bc53 100644 (file)
@@ -715,6 +715,10 @@ public class Gee.TreeSet<G> : AbstractSortedSet<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach (ForallFunc<G> f) {
                        assert (stamp == _set.stamp);
                        if (current != null) {
@@ -1126,6 +1130,10 @@ public class Gee.TreeSet<G> : AbstractSortedSet<G> {
                        }
                }
 
+               public Type element_type {
+                       get { return typeof (G); }
+               }
+
                public void foreach(ForallFunc<G> f) {
                        if(valid)
                                f(get());
index aa4a794..fb8aa80 100644 (file)
@@ -60,7 +60,11 @@ internal class Gee.UnfoldIterator<G> : Object, Traversable<G>, Iterator<G> {
        public bool valid { get { return _current != null; } }
        public bool read_only { get { return true; } }
 
-       public void foreach (ForallFunc f) {
+       public Type element_type {
+               get { return typeof (G); }
+       }
+
+       public void foreach (ForallFunc<G> f) {
                if (_current != null) {
                        f (_current);
                }
index 7a2f9e0..0531be6 100644 (file)
@@ -30,6 +30,7 @@ public abstract class MultiMapTests : Gee.TestCase {
 
        public MultiMapTests (string name) {
                base (name);
+               add_test ("[MultiMap] type correctness", test_type_correctness);
                add_test ("[MultiMap] size", test_size);
                add_test ("[MultiMap] getting and setting", test_getting_setting);
                add_test ("[MultiMap] keys, all keys and values", test_keys_all_keys_values);
@@ -37,6 +38,15 @@ public abstract class MultiMapTests : Gee.TestCase {
 
        protected MultiMap<string,string> test_multi_map;
 
+       public void test_type_correctness () {
+               // Check the multimap exists
+               assert (test_multi_map != null);
+
+               // Check the advertised key and value types
+               assert (test_multi_map.key_type == typeof (string));
+               assert (test_multi_map.value_type == typeof (string));
+       }
+
        private void test_size () {
                // Check the map exists
                assert (test_multi_map != null);