libchamplain_headers = \
champlain.h \
champlain-defines.h \
+ champlain-point.h \
champlain-view.h \
champlain-layer.h \
champlain-base-marker.h \
champlain-map-source.c \
champlain-network-map-source.c \
champlain-map-source-factory.c \
+ champlain-point.c \
champlain-cache.c \
champlain-polygon.c
champlain-base-marker.h \
champlain-marker.h \
champlain-private.h \
+ champlain-point.h \
champlain-map.h \
champlain-zoom-level.h \
champlain-tile.h \
champlain.h \
champlain-view.h \
champlain-defines.h \
+ champlain-point.h \
champlain-enum-types.h \
champlain-layer.h \
champlain-map-source.h \
CHAMPLAIN_STATE_DONE
} ChamplainState;
-typedef struct
-{
- double lat;
- double lon;
-} ChamplainPoint;
-
#endif
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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
{
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;
{
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;
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);
#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>
#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"