[geocode-glib] location: Add equality method



commit 473ffcb22c2f9851b64f2b50a7105f249dc7ed4e
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Mon Nov 14 15:45:17 2016 +0000

    location: Add equality method
    
    Add a method for checking that two #GeocodeLocation instances are equal.
    This will be used in upcoming commits.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774631

 geocode-glib/geocode-glib.symbols |    1 +
 geocode-glib/geocode-location.c   |   37 +++++++++++++++++++++++++++++++++++++
 geocode-glib/geocode-location.h   |    3 +++
 3 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 1ab3425..1218b31 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -5,6 +5,7 @@ geocode_location_new
 geocode_location_new_with_description
 geocode_location_set_from_uri
 geocode_location_to_uri
+geocode_location_equal
 geocode_location_get_accuracy
 geocode_location_get_description
 geocode_location_get_distance_from
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index 15db1b7..bb04ebf 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -113,6 +113,43 @@ geocode_location_get_property (GObject    *object,
         }
 }
 
+/**
+ * geocode_location_equal:
+ * @a: a location
+ * @b: another location
+ *
+ * Compare two #GeocodeLocation instances for equality. This compares all fields
+ * and only returns %TRUE if the instances are exactly equal. For example, if
+ * both locations have the same physical coordinates, but one location has its
+ * #GeocodeLocation:description property set and the other does not, %FALSE
+ * will be returned. Similarly, if both locations have the same
+ * #GeocodeLocation:latitude, #GeocodeLocation:longitude and
+ * #GeocodeLocation:altitude, but a different #GeocodeLocation:accuracy or
+ * #GeocodeLocation:timestamp, %FALSE will be returned. Or if both locations
+ * have the same#GeocodeLocation:latitude and #GeocodeLocation:longitude but a
+ * different #GeocodeLocation:altitude, %FALSE will be returned.
+ *
+ * Both instances must be non-%NULL.
+ *
+ * Returns: %TRUE if the instances are equal, %FALSE otherwise
+ * Since: UNRELEASED
+ */
+gboolean
+geocode_location_equal (GeocodeLocation *a,
+                        GeocodeLocation *b)
+{
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (a), FALSE);
+        g_return_val_if_fail (GEOCODE_IS_LOCATION (b), FALSE);
+
+        return (a->priv->longitude == b->priv->longitude &&
+                a->priv->latitude == b->priv->latitude &&
+                a->priv->altitude == b->priv->altitude &&
+                a->priv->accuracy == b->priv->accuracy &&
+                a->priv->timestamp == b->priv->timestamp &&
+                g_strcmp0 (a->priv->description, b->priv->description) == 0 &&
+                a->priv->crs == b->priv->crs);
+}
+
 static void
 geocode_location_set_latitude (GeocodeLocation *loc,
                                gdouble          latitude)
diff --git a/geocode-glib/geocode-location.h b/geocode-glib/geocode-location.h
index 4805814..ca15b36 100644
--- a/geocode-glib/geocode-location.h
+++ b/geocode-glib/geocode-location.h
@@ -144,6 +144,9 @@ GeocodeLocation *geocode_location_new_with_description (gdouble     latitude,
                                                         gdouble     accuracy,
                                                         const char *description);
 
+gboolean geocode_location_equal                        (GeocodeLocation *a,
+                                                        GeocodeLocation *b);
+
 gboolean geocode_location_set_from_uri                 (GeocodeLocation *loc,
                                                         const char      *uri,
                                                         GError         **error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]