[libgee] Add read_only property to Iterator and MapIterator
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Add read_only property to Iterator and MapIterator
- Date: Tue, 4 Jan 2011 14:50:39 +0000 (UTC)
commit f3d4ac63d29d04e58bdd311b3ebaffbfd6ebae9d
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Tue Jan 4 15:10:52 2011 +0100
Add read_only property to Iterator and MapIterator
gee/abstractmultiset.vala | 6 ++++++
gee/arraylist.vala | 6 ++++++
gee/hashmap.vala | 18 ++++++++++++++++++
gee/hashset.vala | 6 ++++++
gee/iterator.vala | 7 +++++++
gee/linkedlist.vala | 6 ++++++
gee/mapiterator.vala | 14 ++++++++++++++
gee/priorityqueue.vala | 5 +++++
gee/readonlycollection.vala | 6 ++++++
gee/readonlymap.vala | 12 ++++++++++++
gee/treemap.vala | 18 ++++++++++++++++++
gee/treeset.vala | 12 ++++++++++++
tests/testcollection.vala | 1 +
tests/testreadonlycollection.vala | 1 +
14 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/gee/abstractmultiset.vala b/gee/abstractmultiset.vala
index 09804b3..307edd4 100644
--- a/gee/abstractmultiset.vala
+++ b/gee/abstractmultiset.vala
@@ -133,6 +133,12 @@ public abstract class Gee.AbstractMultiSet<G> : AbstractCollection<G>, MultiSet<
_removed = true;
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return ! _removed && _iter.valid;
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index 5ea16bd..fe61418 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -362,6 +362,12 @@ public class Gee.ArrayList<G> : AbstractList<G> {
return _index;
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return _index >= 0 && _index < _list._size && ! _removed;
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index 838ea5c..ad2599c 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -492,6 +492,12 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
return (_next != null);
}
+ public virtual bool read_only {
+ get {
+ return true;
+ }
+ }
+
public bool valid {
get {
return _node != null;
@@ -547,6 +553,18 @@ public class Gee.HashMap<K,V> : Gee.AbstractMap<K,V> {
_map.set (_node.key, value);
_stamp = _map._stamp;
}
+
+ public bool mutable {
+ get {
+ return true;
+ }
+ }
+
+ public override bool read_only {
+ get {
+ return false;
+ }
+ }
}
private class ValueIterator<K,V> : NodeIterator<K,V>, Iterator<K> {
diff --git a/gee/hashset.vala b/gee/hashset.vala
index 073cbd0..d8c1807 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -260,6 +260,12 @@ public class Gee.HashSet<G> : AbstractSet<G> {
_stamp = _set._stamp;
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return _node != null;
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 0183c79..acb120a 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -75,6 +75,13 @@ public interface Gee.Iterator<G> : Object {
public abstract bool valid { get; }
/**
+ * Determines wheather the call to { link remove} is legal assuming the
+ * iterator is valid. The value must not change in runtime hence the user
+ * of iterator may cache it.
+ */
+ public abstract bool read_only { get; }
+
+ /**
* Standard aggragation function.
*
* It takes a function, seed and first element, returns the new seed and
diff --git a/gee/linkedlist.vala b/gee/linkedlist.vala
index 76dc808..28a7f14 100644
--- a/gee/linkedlist.vala
+++ b/gee/linkedlist.vala
@@ -576,6 +576,12 @@ public class Gee.LinkedList<G> : AbstractList<G>, Queue<G>, Deque<G> {
return this._index;
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return !this.removed && this.position != null;
diff --git a/gee/mapiterator.vala b/gee/mapiterator.vala
index 3f7b391..8afada8 100644
--- a/gee/mapiterator.vala
+++ b/gee/mapiterator.vala
@@ -82,5 +82,19 @@ public interface Gee.MapIterator<K,V> : Object {
* { link unset} call and true otherwise.
*/
public abstract bool valid { get; }
+
+ /**
+ * Determines wheather the call to { link set_value} is legal assuming the
+ * iterator is valid. The value must not change in runtime hence the user
+ * of iterator may cache it.
+ */
+ public abstract bool mutable { get; }
+
+ /**
+ * Determines wheather the call to { link unset} is legal assuming the
+ * iterator is valid. The value must not change in runtime hence the user
+ * of iterator may cache it.
+ */
+ public abstract bool read_only { get; }
}
diff --git a/gee/priorityqueue.vala b/gee/priorityqueue.vala
index d4535b9..f6e5897 100644
--- a/gee/priorityqueue.vala
+++ b/gee/priorityqueue.vala
@@ -1006,6 +1006,11 @@ public class Gee.PriorityQueue<G> : Gee.AbstractQueue<G> {
return position;
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
public bool valid {
get {
diff --git a/gee/readonlycollection.vala b/gee/readonlycollection.vala
index 4d80620..4cf8956 100644
--- a/gee/readonlycollection.vala
+++ b/gee/readonlycollection.vala
@@ -164,6 +164,12 @@ internal class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
return _iter.valid;
}
}
+
+ public bool read_only {
+ get {
+ return true;
+ }
+ }
}
public virtual Collection<G> read_only_view {
diff --git a/gee/readonlymap.vala b/gee/readonlymap.vala
index cb22c94..5b0a160 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -246,6 +246,18 @@ internal class Gee.ReadOnlyMap<K,V> : Object, Iterable<Map.Entry<K,V>>, Map<K,V>
assert_not_reached ();
}
+ public bool read_only {
+ get {
+ return true;
+ }
+ }
+
+ public bool mutable {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return _iter.valid;
diff --git a/gee/treemap.vala b/gee/treemap.vala
index c3ae7c3..5cf56dc 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -707,6 +707,12 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
assert (stamp == _map.stamp);
}
+ public virtual bool read_only {
+ get {
+ return true;
+ }
+ }
+
public bool valid {
get {
return current != null;
@@ -772,5 +778,17 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
assert (current != null);
current.value = value;
}
+
+ public override bool read_only {
+ get {
+ return false;
+ }
+ }
+
+ public bool mutable {
+ get {
+ return true;
+ }
+ }
}
}
diff --git a/gee/treeset.vala b/gee/treeset.vala
index 7bf3b07..2dea5e9 100644
--- a/gee/treeset.vala
+++ b/gee/treeset.vala
@@ -704,6 +704,12 @@ public class Gee.TreeSet<G> : AbstractSet<G>, SortedSet<G> {
return current != null;
}
}
+
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
private weak Node<G>? current = null;
private weak Node<G>? _next = null;
@@ -1073,6 +1079,12 @@ public class Gee.TreeSet<G> : AbstractSet<G>, SortedSet<G> {
iterator.remove ();
}
+ public bool read_only {
+ get {
+ return false;
+ }
+ }
+
public bool valid {
get {
return iterator.valid;
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index f8613c2..f662cc6 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -210,6 +210,7 @@ public abstract class CollectionTests : Gee.TestCase {
two_found = true;
// Remove this element
+ assert (! iterator.read_only);
iterator.remove ();
assert (! iterator.valid);
} else if (element == "three") {
diff --git a/tests/testreadonlycollection.vala b/tests/testreadonlycollection.vala
index 75232ff..c2b7fc0 100644
--- a/tests/testreadonlycollection.vala
+++ b/tests/testreadonlycollection.vala
@@ -112,6 +112,7 @@ public class ReadOnlyCollectionTests : Gee.TestCase {
assert (iterator.has_next ());
assert (iterator.next ());
+ assert (iterator.read_only);
if (Test.trap_fork (0, TestTrapFlags.SILENCE_STDOUT |
TestTrapFlags.SILENCE_STDERR)) {
iterator.remove ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]