From ac4295792ed1ca4cb547f615846d8d97bfdf94e4 Mon Sep 17 00:00:00 2001 From: Emmanuel Rodriguez Date: Sat, 13 Jun 2009 17:36:51 +0200 Subject: [PATCH] Champlain::MapSourceFactory has accessors The data structure members have now a Perl accessor. This makes the $desc a more intuive object to use in Perl. --- .../perl/Champlain/t/ChamplainMapSourceDesc.t | 14 ++++----- .../Champlain/xs/ChamplainMapSourceFactory.xs | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t index 5d19bb2..c4e2ad3 100644 --- a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t +++ b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t @@ -33,13 +33,13 @@ sub test_get_set { 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'); + 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()"); diff --git a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs index ef73cf7..6b09a18 100644 --- a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs +++ b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs @@ -88,6 +88,36 @@ 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) -- 2.39.5