[glibmm] Simplify VariantBase .hg code and use it in Settings.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Simplify VariantBase .hg code and use it in Settings.
- Date: Thu, 24 Jun 2010 12:54:02 +0000 (UTC)
commit 9dfa656d7d0aff2ad7590bc74bbf9111a510adb6
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jun 24 14:53:53 2010 +0200
Simplify VariantBase .hg code and use it in Settings.
* glib/src/variant.[hg|ccg]: Use CLASS_OPAQUE_COPYABLE() instead of
_CLASS_GENERIC() to avoid writing some stuff manually. This seems to be OK.
Do not include the C header in our .h file.
* tools/m4/convert_gio.m4: Added GVariantBase conversions.
* gio/src/settings.hg: Added get_value() and set_value().
ChangeLog | 10 +++++++++
gio/src/settings.hg | 4 +++
glib/src/variant.ccg | 50 ++--------------------------------------------
glib/src/variant.hg | 42 +++-----------------------------------
tools/m4/convert_gio.m4 | 4 +++
5 files changed, 25 insertions(+), 85 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8e448b1..4df16f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-06-24 Murray Cumming <murrayc murrayc com>
+
+ Simplify VariantBase .hg code and use it in Settings.
+
+ * glib/src/variant.[hg|ccg]: Use CLASS_OPAQUE_COPYABLE() instead of
+ _CLASS_GENERIC() to avoid writing some stuff manually. This seems to be OK.
+ Do not include the C header in our .h file.
+ * tools/m4/convert_gio.m4: Added GVariantBase conversions.
+ * gio/src/settings.hg: Added get_value() and set_value().
+
2010-06-22 Murray Cumming <murrayc murrayc com>
Clean up glib_functions.defs.
diff --git a/gio/src/settings.hg b/gio/src/settings.hg
index 1a84a84..6388338 100644
--- a/gio/src/settings.hg
+++ b/gio/src/settings.hg
@@ -16,6 +16,7 @@
*/
#include <glibmm/object.h>
+#include <glibmm/variant.h>
#include <giomm/settingsbackend.h>
_DEFS(giomm,gio)
@@ -51,6 +52,9 @@ public:
// FIXME: implement the GVariant stuff
+ _WRAP_METHOD(bool set_value(const Glib::ustring& key, const Glib::VariantBase& value), g_settings_set_value)
+ _WRAP_METHOD(Glib::VariantBase get_value(const Glib::ustring& key), g_settings_get_value)
+
_WRAP_METHOD(int get_int(const Glib::ustring& key) const, g_settings_get_int)
_WRAP_METHOD(void set_int(const Glib::ustring& key, int value), g_settings_set_int)
_WRAP_METHOD(bool get_boolean(const Glib::ustring& key) const, g_settings_get_boolean)
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index a6a2d8d..1d16e4c 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -16,55 +16,11 @@
*/
#include <glibmm/variant.h>
+#include <glib/gvariant.h>
namespace Glib
{
-/**** Glib::VariantBase ****************************************************/
-
-VariantBase::VariantBase()
- : gobject_(0)
-{
-}
-
-VariantBase::VariantBase(GVariant *castitem)
- : gobject_(castitem)
-{
- //TODO: It would be nice to remove a possible floating reference but the C
- //API makes it difficult.
- if(castitem)
- g_variant_ref(castitem);
-}
-
-VariantBase::VariantBase(const VariantBase& other)
-{
- // The copy constructor simply copies the underlying GVariant* and increases
- // its reference. The reference is decreased upon destruction.
- gobject_ = other.gobject_;
-
- if(gobject_)
- g_variant_ref(gobject_);
-}
-
-VariantBase& VariantBase::operator=(const VariantBase& other)
-{
- // Check against self-assignment and simply copy the underlying GVariant*,
- // increasing its reference.
- if( this != &other)
- {
- gobject_ = other.gobject_;
-
- if(gobject_)
- g_variant_ref(gobject_);
- }
- return *this;
-}
-
-VariantBase::~VariantBase()
-{
- if(gobject_)
- g_variant_unref(gobject_);
-}
/****************** Specializations ***********************************/
@@ -74,9 +30,9 @@ const GVariantType* Variant<VariantBase>::variant_type()
return G_VARIANT_TYPE_VARIANT;
}
-Variant<VariantBase> Variant<VariantBase>::create(VariantBase& data)
+Variant<VariantBase> Variant<VariantBase>::create(const VariantBase& data)
{
- return Variant<VariantBase>(g_variant_new_variant(data.gobj()));
+ return Variant<VariantBase>(g_variant_new_variant(const_cast<GVariant*>(data.gobj())));
}
VariantBase Variant<VariantBase>::get() const
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index b1da904..eba1763 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -18,7 +18,6 @@
_DEFS(glibmm,glib)
#include <glibmmconfig.h>
-#include <glib/gvariant.h>
#include <glibmm/ustring.h>
namespace Glib
@@ -40,47 +39,13 @@ namespace Glib
*/
class VariantBase
{
- _CLASS_GENERIC(VariantBase, GVariant)
+ _CLASS_OPAQUE_COPYABLE(VariantBase, GVariant, NONE, g_variant_ref_sink, g_variant_unref)
_IGNORE(g_variant_ref, g_variant_ref_sink, g_variant_unref,
g_variant_get, g_variant_get_va)
public:
- /** Default constructor.
- */
- VariantBase();
-
- /** Constructs a VariantBase from a GVariant.
- * @param casitem The GVariant.
- */
- explicit VariantBase(GVariant* castitem);
-
- /** Copy constructor. Since GVariant is reference counted, the copy
- * constructor simply copies the underlying GVariant* and increases its
- * reference count.
- */
- VariantBase(const VariantBase& other);
-
- /** Assignment operator. Since GVariant is reference counted, assignment
- * simply copies the underlying GVariant* and increases its reference count.
- */
- VariantBase& operator=(const VariantBase& other);
-
- /** Get the underlying GVariant.
- * @return The underlying GVariant.
- */
- GVariant* gobj() { return gobject_; }
-
- /** Get the underlying GVariant.
- * @return The underlying GVariant.
- */
- const GVariant* gobj() const { return gobject_; }
_WRAP_METHOD(bool is_container() const, g_variant_is_container)
_WRAP_METHOD(GVariantClass classify() const, g_variant_classify)
-
- virtual ~VariantBase();
-
-protected:
- GVariant* gobject_;
};
/** Template class from which other Glib::Variant<> specializations derive.
@@ -96,7 +61,7 @@ public:
// Each specialization has (or should have) a variant_type() method that gets
-// the type so the C function can be ignored.
+// the type. So the C g_variant_get_type() function can be ignored.
_IGNORE(g_variant_get_type)
/****************** Specializations ***********************************/
@@ -114,7 +79,8 @@ class Variant<VariantBase> : public VariantBase
Variant<VariantBase>(GVariant* castitem) : VariantBase(castitem) { }
static const GVariantType* variant_type() G_GNUC_CONST;
- static Variant<VariantBase> create(Glib::VariantBase& data);
+ //This must have a create() method because otherwise it would be a copy constructor.
+ static Variant<VariantBase> create(const Glib::VariantBase& data);
_IGNORE(g_variant_new_variant)
VariantBase get() const;
diff --git a/tools/m4/convert_gio.m4 b/tools/m4/convert_gio.m4
index 4a6263c..0daacf3 100644
--- a/tools/m4/convert_gio.m4
+++ b/tools/m4/convert_gio.m4
@@ -130,6 +130,10 @@ _CONVERSION(`GSettings*',`Glib::RefPtr<Settings>',`Glib::wrap($3)')
_CONVERSION(`const Glib::StringArrayHandle&',`const gchar*-const*',`($3).data()')
_CONVERSION(`const Glib::RefPtr<SettingsBackend>&',`GSettingsBackend*',__CONVERT_REFPTR_TO_P)
+
+_CONVERSION(`GVariant*',`Glib::VariantBase',`Glib::wrap($3, true)')
+_CONVERSION(`const Glib::VariantBase&',`GVariant*',`const_cast<GVariant*>(($3).gobj())')
+
#Socket
_CONVERSION(`const Glib::RefPtr<Socket>&',`GSocket*',__CONVERT_CONST_REFPTR_TO_P)
_CONVERSION(`GSocket*',`Glib::RefPtr<Socket>',`Glib::wrap($3)')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]