]> err.no Git - libchamplain/commitdiff
Define ChamplainPoint as a G_TYPE_BOXED
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Fri, 12 Jun 2009 00:40:15 +0000 (20:40 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Fri, 12 Jun 2009 00:40:15 +0000 (20:40 -0400)
champlain/Makefile.am
champlain/champlain-defines.h
champlain/champlain-point.c [new file with mode: 0644]
champlain/champlain-point.h [new file with mode: 0644]
champlain/champlain-polygon.c
champlain/champlain-polygon.h
champlain/champlain.h

index fd5b2ea791e4d298c7d976c0ac5796b33a1301b5..c9922aeed4e4c6903522df88f1e54a30bc169386 100644 (file)
@@ -17,6 +17,7 @@ lib_LTLIBRARIES = libchamplain-0.3.la
 libchamplain_headers = \
        champlain.h                     \
        champlain-defines.h             \
+       champlain-point.h               \
        champlain-view.h                \
        champlain-layer.h               \
        champlain-base-marker.h         \
@@ -46,6 +47,7 @@ libchamplain_0_3_la_SOURCES = \
        champlain-map-source.c          \
        champlain-network-map-source.c  \
        champlain-map-source-factory.c  \
+       champlain-point.c               \
        champlain-cache.c               \
        champlain-polygon.c
 
@@ -55,6 +57,7 @@ noinst_HEADERS = \
        champlain-base-marker.h         \
        champlain-marker.h              \
        champlain-private.h             \
+       champlain-point.h               \
        champlain-map.h                 \
        champlain-zoom-level.h          \
        champlain-tile.h                \
@@ -72,6 +75,7 @@ libchamplain_include_HEADERS = \
        champlain.h                     \
        champlain-view.h                \
        champlain-defines.h             \
+       champlain-point.h               \
        champlain-enum-types.h          \
        champlain-layer.h               \
        champlain-map-source.h          \
index 1f98d31a665b53dbb1e2e22d8d6642a8cb13d795..54056b730bfa0d8182855b7dca2099d3c71a4ee7 100644 (file)
@@ -47,10 +47,4 @@ typedef enum
   CHAMPLAIN_STATE_DONE
 } ChamplainState;
 
-typedef struct
-{
-  double lat;
-  double lon;
-} ChamplainPoint;
-
 #endif
diff --git a/champlain/champlain-point.c b/champlain/champlain-point.c
new file mode 100644 (file)
index 0000000..4997890
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ *
+ * This file is inspired by clutter-color.c which is
+ * Copyright (C) 2006 OpenedHand, and has the same license.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "champlain-point.h"
+
+GType
+champlain_point_get_type (void)
+{
+  static GType type = 0;
+
+  if (G_UNLIKELY (type == 0))
+    {
+      type = g_boxed_type_register_static (g_intern_static_string ("ChamplainPoint"),
+          (GBoxedCopyFunc) champlain_point_copy,
+          (GBoxedFreeFunc) champlain_point_free);
+    }
+
+  return type;
+}
+
+/**
+ * champlain_point_copy:
+ * @point: a #ChamplainPoint
+ *
+ * Makes a copy of the point structure.  The result must be
+ * freed using champlain_point_free().
+ *
+ * Return value: an allocated copy of @point.
+ *
+ * Since: 0.4
+ */
+ChamplainPoint *
+champlain_point_copy (const ChamplainPoint *point)
+{
+  if (G_LIKELY (point != NULL))
+    return g_slice_dup (ChamplainPoint, point);
+
+  return NULL;
+}
+
+/**
+ * champlain_point_free:
+ * @point: a #ChamplainPoint
+ *
+ * Frees a point structure created with #champlain_point_new or
+ * #champlain_point_copy
+ *
+ * Since: 0.4
+ */
+void
+champlain_point_free (ChamplainPoint *point)
+{
+  if (G_LIKELY (point != NULL))
+    g_slice_free (ChamplainPoint, point);
+}
+
+/**
+ * champlain_point_new:
+ * @point: a #ChamplainPoint
+ *
+ * Frees a point structure created with champlain_point_copy().
+ *
+ * Since: 0.4
+ */
+ChamplainPoint *
+champlain_point_new (gdouble lat, gdouble lon)
+{
+  ChamplainPoint *point;
+
+  point = g_slice_new (ChamplainPoint);
+
+  point->lat = lat;
+  point->lon = lon;
+
+  return point;
+}
diff --git a/champlain/champlain-point.h b/champlain/champlain-point.h
new file mode 100644 (file)
index 0000000..3356f92
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
+#error "Only <champlain/champlain.h> can be included directly."
+#endif
+
+#ifndef CHAMPLAIN_POINT_H
+#define CHAMPLAIN_POINT_H
+
+#include <glib-object.h>
+
+typedef struct
+{
+  double lat;
+  double lon;
+} ChamplainPoint;
+
+GType champlain_point_get_type (void) G_GNUC_CONST;
+#define CHAMPLAIN_TYPE_POINT (champlain_point_get_type ())
+
+ChamplainPoint * champlain_point_copy (const ChamplainPoint *point);
+
+void champlain_point_free (ChamplainPoint *point);
+
+ChamplainPoint * champlain_point_new (gdouble lat, gdouble lon);
+
+#endif
index 820ddffaca0c5728c93cdcefa77cdc4d6ee38569..7cb316ee1b91dc1d32a123c17c4e498803c455f8 100644 (file)
@@ -317,9 +317,7 @@ champlain_polygon_append_point (ChamplainPolygon *self,
 {
   g_return_val_if_fail (CHAMPLAIN_IS_POLYGON (self), NULL);
 
-  ChamplainPoint *point = g_new0 (ChamplainPoint, 1);
-  point->lat = lat;
-  point->lon = lon;
+  ChamplainPoint *point = champlain_point_new (lat, lon);
 
   self->priv->points = g_list_append (self->priv->points, point);
   return point;
@@ -346,9 +344,7 @@ champlain_polygon_insert_point (ChamplainPolygon *self,
 {
   g_return_val_if_fail (CHAMPLAIN_IS_POLYGON (self), NULL);
 
-  ChamplainPoint *point = g_new0 (ChamplainPoint, 1);
-  point->lat = lat;
-  point->lon = lon;
+  ChamplainPoint *point = champlain_point_new (lat, lon);
 
   self->priv->points = g_list_insert (self->priv->points, point, pos);
   return point;
@@ -370,7 +366,7 @@ champlain_polygon_clear_points (ChamplainPolygon *self)
   GList *next = self->priv->points;
   while (next != NULL)
   {
-    g_free (next->data);
+    champlain_point_free (next->data);
     next = g_list_next (next);
   }
   g_list_free (self->priv->points);
index 4bdaa74a4ee67c3fe32ac68ddcfa4affc0783816..8671bfaae02690b50c44026966136ce4b7d2c1e3 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef CHAMPLAIN_POLYGON_H
 #define CHAMPLAIN_POLYGON_H
 
-#include <champlain/champlain-defines.h>
+#include <champlain/champlain-point.h>
 
 #include <glib-object.h>
 #include <clutter/clutter.h>
index c8c14b526820e2b79e13586369c2ca7cec0e31d3..7f45eb6497d48446331fa2771b1ea75ef49189ea 100644 (file)
@@ -35,6 +35,7 @@
 #include "champlain/champlain-marker.h"
 #include "champlain/champlain-view.h"
 #include "champlain/champlain-enum-types.h"
+#include "champlain/champlain-point.h"
 #include "champlain/champlain-map-source.h"
 #include "champlain/champlain-map-source-factory.h"
 #include "champlain/champlain-network-map-source.h"