[libgee] Add read_only_view to Gee.MultiMap, fixes bug #687158
- From: Maciej Marcin Piechotka <mpiechotka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgee] Add read_only_view to Gee.MultiMap, fixes bug #687158
- Date: Sat, 16 Feb 2013 13:01:04 +0000 (UTC)
commit ff36eae259f93fc9ef00615da7f072824e5efaed
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date: Sat Feb 16 12:59:56 2013 +0000
Add read_only_view to Gee.MultiMap, fixes bug #687158
gee/Makefile.am | 1 +
gee/abstractmultimap.vala | 15 ++++++++++++++-
gee/multimap.vala | 6 ++++++
gee/readonlymap.vala | 2 +-
4 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/gee/Makefile.am b/gee/Makefile.am
index a129b1f..f67d58a 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -56,6 +56,7 @@ libgee_0_8_la_SOURCES = \
readonlycollection.vala \
readonlylist.vala \
readonlymap.vala \
+ readonlymultimap.vala \
readonlymultiset.vala \
readonlyset.vala \
readonlysortedmap.vala \
diff --git a/gee/abstractmultimap.vala b/gee/abstractmultimap.vala
index 81bd97c..12e84dd 100644
--- a/gee/abstractmultimap.vala
+++ b/gee/abstractmultimap.vala
@@ -309,6 +309,19 @@ public abstract class Gee.AbstractMultiMap<K,V> : Object, MultiMap<K,V> {
public bool mutable { get { return false; } }
}
+ private weak MultiMap<K, V> _read_only_view;
+ public virtual new MultiMap<K, V> read_only_view {
+ owned get {
+ MultiMap<K, V> instance = _read_only_view;
+ if (_read_only_view == null) {
+ instance = new ReadOnlyMultiMap<K, V> (this);
+ _read_only_view = instance;
+ instance.add_weak_pointer ((void**) (&_read_only_view));
+ }
+ return instance;
+ }
+ }
+
// Future-proofing
internal new virtual void reserved0() {}
internal new virtual void reserved1() {}
@@ -319,5 +332,5 @@ public abstract class Gee.AbstractMultiMap<K,V> : Object, MultiMap<K,V> {
internal new virtual void reserved6() {}
internal new virtual void reserved7() {}
internal new virtual void reserved8() {}
- internal new virtual void reserved9() {}
}
+
diff --git a/gee/multimap.vala b/gee/multimap.vala
index 89efe17..01c158f 100644
--- a/gee/multimap.vala
+++ b/gee/multimap.vala
@@ -124,4 +124,10 @@ public interface Gee.MultiMap<K,V> : Object {
* The type of the values in this multimap.
*/
public Type value_type { get { return typeof (V); } }
+
+ public virtual MultiMap<K, V> read_only_view {
+ owned get {
+ return new ReadOnlyMultiMap<K, V> (this);
+ }
+ }
}
diff --git a/gee/readonlymap.vala b/gee/readonlymap.vala
index 7d2e7bf..f916d85 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -244,7 +244,7 @@ internal class Gee.ReadOnlyMap<K,V> : Object, Traversable<Map.Entry<K,V>>, Itera
return _map.chop (offset, length);
}
- protected class MapIterator<K,V> : Object, Gee.MapIterator<K,V> {
+ internal class MapIterator<K,V> : Object, Gee.MapIterator<K,V> {
protected Gee.MapIterator<K,V> _iter;
public MapIterator (Gee.MapIterator<K,V> iterator) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]