[glibmm] Glib::VariantBase: Add operator==() and operator!=()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Glib::VariantBase: Add operator==() and operator!=()
- Date: Tue, 14 Nov 2017 16:04:53 +0000 (UTC)
commit ba5483c728d19e782ee838b0deb001fdf41a69ba
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue Nov 14 17:01:00 2017 +0100
Glib::VariantBase: Add operator==() and operator!=()
operator==() is equivalent to VariantBase::equal(). Bug 789330
glib/src/variant.ccg | 48 +++++++++++++++++++++++++++++--------------
glib/src/variant.hg | 54 ++++++++++++++++++++++++++++++-------------------
2 files changed, 65 insertions(+), 37 deletions(-)
---
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index 6a2a6a9..bf9c12a 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -22,6 +22,8 @@
namespace Glib
{
+/****************** VariantBase ***********************************/
+
VariantBase::VariantBase(GVariant* castitem, bool make_a_copy /* = false */)
{
if (castitem)
@@ -36,6 +38,32 @@ VariantBase::VariantBase(GVariant* castitem, bool make_a_copy /* = false */)
gobject_ = castitem;
}
+VariantBase::operator bool() const
+{
+ return gobj();
+}
+
+void
+VariantBase::init(const GVariant* cobject, bool take_a_reference)
+{
+ if (gobject_)
+ g_variant_unref(gobject_);
+
+ gobject_ = const_cast<GVariant*>(cobject);
+ if (take_a_reference)
+ g_variant_ref(gobject_);
+}
+
+bool VariantBase::operator==(const VariantBase& other) const
+{
+ return equal(other);
+}
+
+bool VariantBase::operator!=(const VariantBase& other) const
+{
+ return !equal(other);
+}
+
void
VariantBase::get_normal_form(VariantBase& result) const
{
@@ -108,6 +136,8 @@ VariantBase::is_castable_to(const VariantType& supertype) const
return true;
}
+/****************** VariantStringBase ***********************************/
+
VariantStringBase::VariantStringBase() : VariantBase()
{
}
@@ -137,6 +167,8 @@ VariantStringBase::create_signature(VariantStringBase& output, const std::string
output.init(result);
}
+/****************** VariantContainerBase ***********************************/
+
VariantContainerBase::VariantContainerBase() : VariantBase()
{
}
@@ -244,22 +276,6 @@ VariantContainerBase::get_iter(const VariantType& container_variant_type) const
/****************** Specializations ***********************************/
-VariantBase::operator bool() const
-{
- return gobj();
-}
-
-void
-VariantBase::init(const GVariant* cobject, bool take_a_reference)
-{
- if (gobject_)
- g_variant_unref(gobject_);
-
- gobject_ = const_cast<GVariant*>(cobject);
- if (take_a_reference)
- g_variant_ref(gobject_);
-}
-
/*--------------------Variant<VariantBase>---------------------*/
Variant<VariantBase>::Variant() : VariantContainerBase()
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 9a16511..a8b246a 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -143,6 +143,39 @@ public:
*/
_WRAP_METHOD(bool equal(const VariantBase& other) const, g_variant_equal)
+ /** Checks if @a *this and @a other have the same type and value.
+ *
+ * @newin{2,56}
+ *
+ * @param other The Variant to compare with.
+ * @return <tt>true</tt> if @a *this and @a other are equal.
+ */
+ bool operator==(const VariantBase& other) const;
+
+ /** Checks if @a *this and @a other have the same type and value.
+ *
+ * @newin{2,56}
+ *
+ * @param other The Variant to compare with.
+ * @return <tt>true</tt> if @a *this and @a other are not equal.
+ */
+ bool operator!=(const VariantBase& other) const;
+
+ /** Ordering relational operators.
+ * These are explicitly deleted to prevent the compiler from generating
+ * error messages containing long lists of operators that can't be used.
+ */
+ bool operator<(const VariantBase& other) const = delete;
+
+ /// See operator<().
+ bool operator<=(const VariantBase& other) const = delete;
+
+ /// See operator<().
+ bool operator>(const VariantBase& other) const = delete;
+
+ /// See operator<().
+ bool operator>=(const VariantBase& other) const = delete;
+
/** Gets a VariantBase instance that has the same value as this variant and
* is trusted to be in normal form.
*
@@ -223,27 +256,6 @@ protected:
*/
bool is_castable_to(const VariantType& supertype) const;
#endif //DOXYGEN_SHOULD_SKIP_THIS
-
-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]