[libgee] Add *_type property for all collections, fixes bug #663337



commit b62ed44ad3be999ef1d663845589bbf9f31072b6
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Mon Dec 19 17:58:29 2011 +0100

    Add *_type property for all collections, fixes bug #663337

 gee/abstractmultimap.vala   |    4 ++++
 gee/abstractmultiset.vala   |    4 ++++
 gee/arraylist.vala          |    4 ++++
 gee/concurrentlist.vala     |    4 ++++
 gee/hashmap.vala            |   12 ++++++++++++
 gee/hashset.vala            |    4 ++++
 gee/linkedlist.vala         |    4 ++++
 gee/multimap.vala           |   10 ++++++++++
 gee/priorityqueue.vala      |    4 ++++
 gee/readonlycollection.vala |    8 ++++++--
 gee/traversable.vala        |    3 +--
 gee/treemap.vala            |   24 ++++++++++++++++++++++++
 gee/treeset.vala            |    8 ++++++++
 gee/unfolditerator.vala     |    6 +++++-
 tests/testmultimap.vala     |   10 ++++++++++
 15 files changed, 104 insertions(+), 5 deletions(-)
---
diff --git a/gee/abstractmultimap.vala b/gee/abstractmultimap.vala
index ed547eb..61f8a01 100644
--- a/gee/abstractmultimap.vala
+++ b/gee/abstractmultimap.vala
@@ -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); } }
 }
diff --git a/gee/abstractmultiset.vala b/gee/abstractmultiset.vala
index fc9fe7d..147fb7e 100644
--- a/gee/abstractmultiset.vala
+++ b/gee/abstractmultiset.vala
@@ -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);
 		}
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index a051378..3f7018e 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -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)
diff --git a/gee/concurrentlist.vala b/gee/concurrentlist.vala
index 91bfa22..356157d 100644
--- a/gee/concurrentlist.vala
+++ b/gee/concurrentlist.vala
@@ -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)
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index 57f1412..d71d964 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -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));
diff --git a/gee/hashset.vala b/gee/hashset.vala
index 85152f5..3e8ae01 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -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)
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index fb8fae5..575c63b 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -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) {
diff --git a/gee/multimap.vala b/gee/multimap.vala
index 373ac08..8069c8e 100644
--- a/gee/multimap.vala
+++ b/gee/multimap.vala
@@ -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; }
 }
diff --git a/gee/priorityqueue.vala b/gee/priorityqueue.vala
index b1a07ad..e40676b 100644
--- a/gee/priorityqueue.vala
+++ b/gee/priorityqueue.vala
@@ -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);
diff --git a/gee/readonlycollection.vala b/gee/readonlycollection.vala
index df5d986..fcf76f4 100644
--- a/gee/readonlycollection.vala
+++ b/gee/readonlycollection.vala
@@ -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);
 		}
diff --git a/gee/traversable.vala b/gee/traversable.vala
index 9af35eb..c8219c2 100644
--- a/gee/traversable.vala
+++ b/gee/traversable.vala
@@ -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. 
 	 *
diff --git a/gee/treemap.vala b/gee/treemap.vala
index 02587c6..2b8d05b 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -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));
diff --git a/gee/treeset.vala b/gee/treeset.vala
index 6bcc0a5..342bc53 100644
--- a/gee/treeset.vala
+++ b/gee/treeset.vala
@@ -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());
diff --git a/gee/unfolditerator.vala b/gee/unfolditerator.vala
index aa4a794..fb8aa80 100644
--- a/gee/unfolditerator.vala
+++ b/gee/unfolditerator.vala
@@ -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);
 		}
diff --git a/tests/testmultimap.vala b/tests/testmultimap.vala
index 7a2f9e0..0531be6 100644
--- a/tests/testmultimap.vala
+++ b/tests/testmultimap.vala
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]