[glibmm] Implemented reference counting for BalancedTree.
- From: Jonathon Jongsma <jjongsma src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glibmm] Implemented reference counting for BalancedTree.
- Date: Wed, 6 Jan 2010 05:17:05 +0000 (UTC)
commit 199929dd8a4050776332813e7125ce5bba923e5c
Author: Szilárd Pfeiffer <mailbox pfeifferszilard hu>
Date: Tue Jan 5 22:40:07 2010 -0600
Implemented reference counting for BalancedTree.
glib/src/btree.hg | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/glib/src/btree.hg b/glib/src/btree.hg
index a815ae1..0061819 100644
--- a/glib/src/btree.hg
+++ b/glib/src/btree.hg
@@ -38,6 +38,7 @@ public:
typedef sigc::slot<bool, const K&, const V&> TraverseFunc;
typedef sigc::slot<int, const K&, const K&> CompareFunc;
+protected:
BalancedTree() :
key_compare_slot(sigc::ptr_fun(key_compare))
{
@@ -50,6 +51,17 @@ public:
gobject_ = g_tree_new_full(on_compare_tree, &key_compare_slot, on_destroy_key, on_destroy_value);
}
+public:
+ static Glib::RefPtr< BalancedTree<K, V> > create()
+ {
+ return Glib::RefPtr< BalancedTree<K, V> >(new BalancedTree());
+ }
+
+ static Glib::RefPtr< BalancedTree<K, V> > create(const CompareFunc &key_compare_slot)
+ {
+ return Glib::RefPtr< BalancedTree<K, V> >(new BalancedTree(key_compare_slot));
+ }
+
~BalancedTree()
{
g_tree_destroy(gobject_);
@@ -69,6 +81,34 @@ public:
}
/**
+ * reference:
+ *
+ * Increments the reference count of tree by one. It is safe to call
+ * this function from any thread.
+ **/
+ void reference()
+ {
+ g_tree_ref(gobject_);
+ }
+ _IGNORE(g_tree_ref)
+
+/**
+ * unreference:
+ *
+ * Decrements the reference count of tree by one. If the reference count
+ * drops to 0, all keys and values will be destroyed (if destroy
+ * functions were specified) and all memory allocated by @tree will be
+ * released.
+ *
+ * It is safe to call this function from any thread.
+ **/
+ void unreference()
+ {
+ g_tree_unref(gobject_);
+ }
+ _IGNORE(g_tree_unref)
+
+/**
* insert:
* @key: the key to insert.
* @value: the value corresponding to the key.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]