[glibmm] VariantBase: Add operator for BoolExpr (const void*).
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] VariantBase: Add operator for BoolExpr (const void*).
- Date: Tue, 18 Dec 2012 15:16:00 +0000 (UTC)
commit 459b12d0c7cb33e503b730d84b7275e9f8cf3682
Author: Andrew Potter <agpotter gmail com>
Date: Tue Dec 18 16:10:58 2012 +0100
VariantBase: Add operator for BoolExpr (const void*).
* glib/src/variant.{ccg,hg}: Adds operator BoolExpr.
Also deletes relational operators to prevent unexpected conversion.
Bug #690121.
ChangeLog | 8 ++++++++
glib/src/variant.ccg | 5 +++++
glib/src/variant.hg | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0ef9101..ca5bb60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-12-18 Andrew Potter <agpotter gmail com>
+
+ VariantBase: Add operator for BoolExpr (const void*).
+
+ * glib/src/variant.{ccg,hg}: Adds operator BoolExpr.
+ Also deletes relational operators to prevent unexpected conversion.
+ Bug #690121.
+
2012-12-13 Andrew Potter <agpotter gmail com>
SimpleAction: Fix stateful action constructor typo, allowing use.
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index b7f4f52..dea7391 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -182,6 +182,11 @@ bool VariantContainerBase::get_maybe(VariantBase& maybe) const
/****************** Specializations ***********************************/
+VariantBase::operator const void*() const
+{
+ return gobj() ? GINT_TO_POINTER(1) : 0;
+}
+
void VariantBase::init(const GVariant* cobject, bool take_a_reference)
{
if(gobject_)
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 046b270..19e84f8 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -87,6 +87,23 @@ class VariantBase
g_variant_get, g_variant_get_va)
public:
+ /** This typedef is just to make it more obvious that
+ * our operator const void* should be used like operator bool().
+ */
+ typedef const void* BoolExpr;
+
+ /** Test whether the Variant has an underlying instance.
+ *
+ * Mimics usage of pointers:
+ * @code
+ * if (variant)
+ * do_something();
+ * @endcode
+ *
+ * @newin{2,36}
+ */
+ operator BoolExpr() const;
+
/** Replace the underlying GVariant.
* This is for use by methods that take a VariantBase& as an output
* parameter.
@@ -175,6 +192,26 @@ public:
template<class V_CastTo>
static V_CastTo cast_dynamic(const VariantBase& v) throw(std::bad_cast);
+private:
+ /** Relational operators are deleted to prevent invalid conversion
+ * to const void*.
+ */
+ bool operator<(const VariantBase& src) const;
+
+ /// See operator<().
+ bool operator<=(const VariantBase& src) const;
+
+ /// See operator<().
+ bool operator>(const VariantBase& src) const;
+
+ /// See operator<().
+ bool operator>=(const VariantBase& src) const;
+
+ /// See operator<().
+ bool operator==(const VariantBase& src) const;
+
+ /// See operator<().
+ bool operator!=(const VariantBase& src) const;
};
template<class V_CastTo>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]