[libchamplain] The accessors/modifiers are now done through XS.
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: svn-commits-list gnome org
- Subject: [libchamplain] The accessors/modifiers are now done through XS.
- Date: Sun, 14 Jun 2009 11:12:34 -0400 (EDT)
commit 612026decf32fa29c9baccdb1a4157bfd7d82444
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date: Sun Jun 14 12:58:04 2009 +0200
The accessors/modifiers are now done through XS.
Before the object wasn't registered as a GType and all marshalling had to be
done by hand. Furthermore the C structure was transformed into a Per hash
making the hash fields out of sync with the C structure. Now that the object is
a GType (GBoxed) everything is more natural.
bindings/perl/Champlain/lib/Champlain.pm | 16 ----------
bindings/perl/Champlain/t/ChamplainMapSourceDesc.t | 30 +++++++------------
.../perl/Champlain/xs/ChamplainMapSourceFactory.xs | 30 --------------------
3 files changed, 11 insertions(+), 65 deletions(-)
---
diff --git a/bindings/perl/Champlain/lib/Champlain.pm b/bindings/perl/Champlain/lib/Champlain.pm
index 38164f2..eb08236 100644
--- a/bindings/perl/Champlain/lib/Champlain.pm
+++ b/bindings/perl/Champlain/lib/Champlain.pm
@@ -149,20 +149,4 @@ __PACKAGE__->bootstrap($VERSION);
package Champlain::MapSourceDesc;
-BEGIN {
- # Create getters and setters for the properties
- my @properties = qw(
- id name license license_uri min_zoom_level max_zoom_level projection
- );
- foreach my $property (@properties) {
- my $get_name = join '::', __PACKAGE__, "get_$property";
- my $set_same = join '::', __PACKAGE__, "set_$property";
- my $getter = sub {return $_[0]->{$property};};
- my $setter = sub {return $_[0]->{$property} = $_[1];};
- no strict;
- *{$get_name} = $getter;
- *{$set_same} = $setter;
- }
-}
-
1;
diff --git a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t
index c4e2ad3..5b88650 100644
--- a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t
+++ b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Clutter::TestHelper tests => 25;
+use Clutter::TestHelper tests => 18;
use Champlain ':maps';
@@ -24,31 +24,23 @@ sub test_get_set {
ok(@maps >= 5, "Maps factory has the default maps");
# Find the OAM map and check that the it's properly described
- my @found = grep { $_->{id} eq Champlain::MapSourceFactory->OAM } @maps;
- is(scalar(@found), 1);
+ my @found = grep { $_->get_id eq Champlain::MapSourceFactory->OAM } @maps;
+ is(scalar(@found), 1, "Found a single map matching OAM");
if (! @found) {
fail("Can't test a Champlain::MapSourceDesc without a map description") for 1 .. 22;
return;
}
+ # Getters
my ($oam) = @found;
isa_ok($oam, 'Champlain::MapSourceDesc');
- is($oam->id, Champlain::MapSourceFactory->OAM);
- is($oam->name, 'OpenAerialMap');
- is($oam->license, "(CC) BY 3.0 OpenAerialMap contributors");
- is($oam->license_uri, 'http://creativecommons.org/licenses/by/3.0/');
- is($oam->min_zoom_level, 0);
- is($oam->max_zoom_level, 17);
- is($oam->projection, 'mercator');
-
- # Getters
- is($oam->get_id, $oam->{id}, "get_id()");
- is($oam->get_name, $oam->{name}, "get_name()");
- is($oam->get_license, $oam->{license}, "get_license()");
- is($oam->get_license_uri, $oam->{license_uri}, "get_license_uri()");
- is($oam->get_min_zoom_level, $oam->{min_zoom_level}, "get_min_zoom_level()");
- is($oam->get_max_zoom_level, $oam->{max_zoom_level}, "get_max_zoom_level()");
- is($oam->get_projection, $oam->{projection}, "get_projection()");
+ is($oam->get_id, Champlain::MapSourceFactory->OAM, "get_id()");
+ is($oam->get_name, 'OpenAerialMap', "get_name()");
+ is($oam->get_license, "(CC) BY 3.0 OpenAerialMap contributors", "get_license()");
+ is($oam->get_license_uri, 'http://creativecommons.org/licenses/by/3.0/', "get_license_uri()");
+ is($oam->get_min_zoom_level, 0, "get_min_zoom_level()");
+ is($oam->get_max_zoom_level, 17, "get_max_zoom_level()");
+ is($oam->get_projection, 'mercator', "get_projection()");
# Setters
diff --git a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs
index 6b09a18..ef73cf7 100644
--- a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs
+++ b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs
@@ -88,36 +88,6 @@ champlain_map_source_factory_register (ChamplainMapSourceFactory *factory, SV *s
OUTPUT:
RETVAL
-/**
- * Provide nice accessors to the data members of the struct.
- */
-SV*
-id (ChamplainMapSourceDesc *desc)
- ALIAS:
- Champlain::MapSourceDesc::name = 1
- Champlain::MapSourceDesc::license = 2
- Champlain::MapSourceDesc::license_uri = 3
- Champlain::MapSourceDesc::min_zoom_level = 4
- Champlain::MapSourceDesc::max_zoom_level = 5
- Champlain::MapSourceDesc::projection = 6
-
- CODE:
- switch (ix) {
- case 0: RETVAL = newSVGChar(desc->id); break;
- case 1: RETVAL = newSVGChar(desc->name); break;
- case 2: RETVAL = newSVGChar(desc->license); break;
- case 3: RETVAL = newSVGChar(desc->license_uri); break;
- case 4: RETVAL = newSViv(desc->min_zoom_level); break;
- case 5: RETVAL = newSViv(desc->max_zoom_level); break;
- case 6: RETVAL = newSVChamplainMapProjection(desc->projection); break;
- default:
- RETVAL = &PL_sv_undef;
- g_assert_not_reached ();
- }
-
- OUTPUT:
- RETVAL
-
const gchar*
OSM_MAPNIK (class)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]