From: Emmanuel Rodriguez Date: Sun, 14 Jun 2009 14:46:02 +0000 (+0200) Subject: Bindings for ChamplainPoint X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5b44316868e3738c43fcda3d1e87715dcd3d3cb;p=libchamplain Bindings for ChamplainPoint --- diff --git a/bindings/perl/Champlain/MANIFEST b/bindings/perl/Champlain/MANIFEST index 024f42e..6f81967 100644 --- a/bindings/perl/Champlain/MANIFEST +++ b/bindings/perl/Champlain/MANIFEST @@ -16,6 +16,7 @@ xs/ChamplainMapSourceDesc.xs xs/ChamplainMapSourceFactory.xs xs/ChamplainMarker.xs xs/ChamplainNetworkMapSource.xs +xs/ChamplainPoint.xs xs/ChamplainTile.xs xs/ChamplainView.xs xs/ChamplainZoomLevel.xs @@ -28,6 +29,7 @@ t/ChamplainMapSourceDesc.t t/ChamplainMapSourceFactory.t t/ChamplainMarker.t t/ChamplainNetworkMapSource.t +t/ChamplainPoint.t t/ChamplainTile.t t/ChamplainView.t t/ChamplainZoomLevel.t diff --git a/bindings/perl/Champlain/maps b/bindings/perl/Champlain/maps index aaf00cc..12be7ba 100644 --- a/bindings/perl/Champlain/maps +++ b/bindings/perl/Champlain/maps @@ -12,3 +12,4 @@ CHAMPLAIN_TYPE_STATE ChamplainState GEnum Champlain CHAMPLAIN_TYPE_MAP_SOURCE_FACTORY ChamplainMapSourceFactory GObject Champlain::MapSourceFactory CHAMPLAIN_TYPE_CACHE ChamplainCache GObject Champlain::Cache CHAMPLAIN_TYPE_MAP_SOURCE_DESC ChamplainMapSourceDesc GBoxed Champlain::MapSourceDesc +CHAMPLAIN_TYPE_POINT ChamplainPoint GBoxed Champlain::Point diff --git a/bindings/perl/Champlain/t/ChamplainPoint.t b/bindings/perl/Champlain/t/ChamplainPoint.t new file mode 100644 index 0000000..e791efb --- /dev/null +++ b/bindings/perl/Champlain/t/ChamplainPoint.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Clutter::TestHelper tests => 10; +use Test::Exception; + +use Champlain ':maps'; + +exit tests(); + +sub tests { + test_generic(); + return 0; +} + + +sub test_generic { + my $point = Champlain::Point->new(10.2, 34.5); + isa_ok($point, 'Champlain::Point'); + + is($point->lat, 10.2, "point->lat()"); + is($point->lon, 34.5, "point->lon()"); + + + # Copy the point + my $copy = $point->copy; + isa_ok($copy, 'Champlain::Point'); + is($copy->lat, $point->lat, "lat of copy is identical to the original"); + is($copy->lon, $point->lon, "lon of copy is identical to the original"); + + + # Modify the copy + $copy->lat(-45.03); + is($copy->lat, -45.03, "point->lat(x)"); + is($point->lat, 10.2, "point->lat()"); + + $copy->lon(74.364); + is($copy->lon, 74.364, "point->lon(y)"); + is($point->lon, 34.5, "point->lon()"); +} diff --git a/bindings/perl/Champlain/xs/ChamplainPoint.xs b/bindings/perl/Champlain/xs/ChamplainPoint.xs new file mode 100644 index 0000000..12c04b5 --- /dev/null +++ b/bindings/perl/Champlain/xs/ChamplainPoint.xs @@ -0,0 +1,47 @@ +#include "champlain-perl.h" + + +MODULE = Champlain::Point PACKAGE = Champlain::Point PREFIX = champlain_point_ + + +ChamplainPoint* +champlain_point_new (class, gdouble lat, gdouble lon) + C_ARGS: lat, lon + + +ChamplainPoint* +champlain_point_copy (const ChamplainPoint* point) + + +void +champlain_point_free (ChamplainPoint* point) + + +# +# Provide nice accessors to the data members of the struct. +# +gdouble +lat (ChamplainPoint *point, gdouble newval = 0) + ALIAS: + lon = 1 + + CODE: + switch (ix) { + case 0: + RETVAL = point->lat; + if (items > 1) point->lat = newval; + break; + + case 1: + RETVAL = point->lon; + if (items > 1) point->lon = newval; + break; + + default: + RETVAL = 0.0; + g_assert_not_reached(); + break; + } + + OUTPUT: + RETVAL