[libgee] Introduce Map.key_type and Map.value_type
- From: Didier Villevalois <dvillevalois src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgee] Introduce Map.key_type and Map.value_type
- Date: Wed, 23 Sep 2009 22:52:20 +0000 (UTC)
commit b352555561eb9ff7b2c0090be518c4de74114c9b
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Thu Sep 24 00:51:55 2009 +0200
Introduce Map.key_type and Map.value_type
gee/abstractmap.vala | 14 ++++++++++++++
gee/map.vala | 10 ++++++++++
gee/readonlymap.vala | 14 ++++++++++++++
tests/testmap.vala | 10 ++++++++++
4 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/gee/abstractmap.vala b/gee/abstractmap.vala
index e798876..8e7ab9f 100644
--- a/gee/abstractmap.vala
+++ b/gee/abstractmap.vala
@@ -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>); }
}
diff --git a/gee/map.vala b/gee/map.vala
index f085c5f..917cff3 100644
--- a/gee/map.vala
+++ b/gee/map.vala
@@ -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
diff --git a/gee/readonlymap.vala b/gee/readonlymap.vala
index d89ba1e..3bf164b 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -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>); }
}
diff --git a/tests/testmap.vala b/tests/testmap.vala
index 3254482..e416263 100644
--- a/tests/testmap.vala
+++ b/tests/testmap.vala
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]