From: Emmanuel Rodriguez Date: Sun, 14 Jun 2009 21:35:32 +0000 (+0200) Subject: Accesors/Modifiers for Chamlain::MapSourceDesc are now without prefix (get_/get_). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=589705e0c7879ce1ca47b3c68a490b09a99052d5;p=libchamplain Accesors/Modifiers for Chamlain::MapSourceDesc are now without prefix (get_/get_). The prefixes get_ and set_ have been removed because the ChamplainMapSourceDesc is a struct and not a GObject. By using property names the caller will notice that the fields are directly accessed. --- diff --git a/bindings/perl/Champlain/examples/gtk2.pl b/bindings/perl/Champlain/examples/gtk2.pl index b6e2263..4071d70 100755 --- a/bindings/perl/Champlain/examples/gtk2.pl +++ b/bindings/perl/Champlain/examples/gtk2.pl @@ -126,14 +126,14 @@ sub create_combo_box { my $index = 0; my $current_source = $map->get_map_source->get_id; my $factory = Champlain::MapSourceFactory->dup_default; - foreach my $desc (sort { $a->get_name cmp $b->get_name } $factory->dup_list) { + foreach my $desc (sort { $a->name cmp $b->name } $factory->dup_list) { my $iter = $model->append(); $model->set($iter, - 0, $desc->get_name, - 1, $desc->get_id, + 0, $desc->name, + 1, $desc->id, ); - if ($current_source eq $desc->get_id) { + if ($current_source eq $desc->id) { $active = $index; } diff --git a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t index d2b4820..2e91733 100644 --- a/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t +++ b/bindings/perl/Champlain/t/ChamplainMapSourceDesc.t @@ -25,7 +25,7 @@ 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 { $_->get_id eq Champlain::MapSourceFactory->OAM } @maps; + my @found = grep { $_->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; @@ -35,43 +35,43 @@ sub test_get_set { # Getters my ($oam) = @found; isa_ok($oam, 'Champlain::MapSourceDesc'); - 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()"); - is($oam->get_uri_format, 'http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z#/#X#/#Y#.jpg', "get_uri_format()"); + is($oam->id, Champlain::MapSourceFactory->OAM, "get id()"); + is($oam->name, 'OpenAerialMap', "get name()"); + is($oam->license, "(CC) BY 3.0 OpenAerialMap contributors", "get license()"); + is($oam->license_uri, 'http://creativecommons.org/licenses/by/3.0/', "get license_uri()"); + is($oam->min_zoom_level, 0, "get min_zoom_level()"); + is($oam->max_zoom_level, 17, "get max_zoom_level()"); + is($oam->projection, 'mercator', "get projection()"); + is($oam->uri_format, 'http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z#/#X#/#Y#.jpg', "get uri_format()"); # Setters - $oam->set_id('test'); - is($oam->get_id, 'test', "set_id()"); + $oam->id('test'); + is($oam->id, 'test', "set id()"); - $oam->set_name("new name"); - is($oam->get_name, "new name", "set_name()"); + $oam->name("new name"); + is($oam->name, "new name", "set name()"); - $oam->set_license("free for all"); - is($oam->get_license, "free for all", "set_license()"); + $oam->license("free for all"); + is($oam->license, "free for all", "set license()"); - $oam->set_license_uri('file:///tmp/free.txt'); - is($oam->get_license_uri, 'file:///tmp/free.txt', "set_license_uri()"); + $oam->license_uri('file:///tmp/free.txt'); + is($oam->license_uri, 'file:///tmp/free.txt', "set license_uri()"); - $oam->set_min_zoom_level(2); - is($oam->get_min_zoom_level, 2, "set_min_zoom_level()"); + $oam->min_zoom_level(2); + is($oam->min_zoom_level, 2, "set min_zoom_level()"); - $oam->set_max_zoom_level(4); - is($oam->get_max_zoom_level, 4, "set_max_zoom_level()"); + $oam->max_zoom_level(4); + is($oam->max_zoom_level, 4, "set max_zoom_level()"); # There are no other projections now, we have to trust that the setter works - $oam->set_projection('mercator'); - is($oam->get_projection, 'mercator', "set_projection()"); + $oam->projection('mercator'); + is($oam->projection, 'mercator', "set projection()"); - $oam->set_uri_format('http://tile.oam.org/tiles/#Z#/#X#/#Y#.jpg'); - is($oam->get_uri_format, 'http://tile.oam.org/tiles/#Z#/#X#/#Y#.jpg', "set_uri_format()"); + $oam->uri_format('http://tile.oam.org/tiles/#Z#/#X#/#Y#.jpg'); + is($oam->uri_format, 'http://tile.oam.org/tiles/#Z#/#X#/#Y#.jpg', "set uri_format()"); # The constructor is not yet available in the perl bindings - throws_ok { $oam->get_constructor } qr/\Qdesc->get_constructor() isn't implemented yet/, "get_constructor() isn't implemented"; - throws_ok { $oam->set_constructor(sub{}) } qr/\Qdesc->set_constructor(\&code_ref)/, "set_constructor() isn't implemented"; + throws_ok { $oam->constructor } qr/\Qdesc->constructor() isn't implemented yet/, "get constructor() isn't implemented"; + throws_ok { $oam->constructor(sub{}) } qr/\Qdesc->constructor(\&code_ref)/, "set constructor() isn't implemented"; } diff --git a/bindings/perl/Champlain/xs/ChamplainMapSourceDesc.xs b/bindings/perl/Champlain/xs/ChamplainMapSourceDesc.xs index 7949bee..61cb734 100644 --- a/bindings/perl/Champlain/xs/ChamplainMapSourceDesc.xs +++ b/bindings/perl/Champlain/xs/ChamplainMapSourceDesc.xs @@ -18,57 +18,70 @@ champlain_map_source_desc_free (ChamplainMapSourceDesc* desc) # -# Provide nice accessors to the data members of the struct. +# Provide nice accessors and modifiers to the data members of the struct. # SV* -get_id (ChamplainMapSourceDesc *desc) +id (ChamplainMapSourceDesc *desc, ...) ALIAS: - Champlain::MapSourceDesc::get_name = 1 - Champlain::MapSourceDesc::get_license = 2 - Champlain::MapSourceDesc::get_license_uri = 3 - Champlain::MapSourceDesc::get_min_zoom_level = 4 - Champlain::MapSourceDesc::get_max_zoom_level = 5 - Champlain::MapSourceDesc::get_projection = 6 - Champlain::MapSourceDesc::get_constructor = 7 - Champlain::MapSourceDesc::get_uri_format = 8 + name = 1 + license = 2 + license_uri = 3 + min_zoom_level = 4 + max_zoom_level = 5 + projection = 6 + constructor = 7 + uri_format = 8 CODE: switch (ix) { case 0: RETVAL = newSVGChar(desc->id); + if (items > 1) desc->id = g_strdup(SvGChar(ST(1))); break; case 1: RETVAL = newSVGChar(desc->name); + if (items > 1) desc->name = g_strdup(SvGChar(ST(1))); break; case 2: RETVAL = newSVGChar(desc->license); + if (items > 1) desc->license = g_strdup(SvGChar(ST(1))); break; case 3: RETVAL = newSVGChar(desc->license_uri); + if (items > 1) desc->license_uri = g_strdup(SvGChar(ST(1))); break; case 4: RETVAL = newSViv(desc->min_zoom_level); + if (items > 1) desc->min_zoom_level = (gint)SvIV(ST(1)); break; case 5: RETVAL = newSViv(desc->max_zoom_level); + if (items > 1) desc->max_zoom_level = (gint)SvIV(ST(1)); break; case 6: RETVAL = newSVChamplainMapProjection(desc->projection); + if (items > 1) desc->projection = SvChamplainMapProjection(ST(1)); break; case 7: /* This is tricky as we have to wrap the C callback into a Perl sub. */ - croak("$desc->get_constructor() isn't implemented yet"); + if (items == 1) { + croak("$desc->constructor() isn't implemented yet"); + } + else { + croak("$desc->constructor(\\&code_ref) isn't implemented yet"); + } break; case 8: RETVAL = newSVGChar(desc->uri_format); + if (items > 1) desc->uri_format = g_strdup(SvGChar(ST(1))); break; default: @@ -79,63 +92,3 @@ get_id (ChamplainMapSourceDesc *desc) OUTPUT: RETVAL - - -# -# Provide nice modifiers to the data members of the struct. -# -void -set_id (ChamplainMapSourceDesc *desc, SV *sv) - ALIAS: - Champlain::MapSourceDesc::set_name = 1 - Champlain::MapSourceDesc::set_license = 2 - Champlain::MapSourceDesc::set_license_uri = 3 - Champlain::MapSourceDesc::set_min_zoom_level = 4 - Champlain::MapSourceDesc::set_max_zoom_level = 5 - Champlain::MapSourceDesc::set_projection = 6 - Champlain::MapSourceDesc::set_constructor = 7 - Champlain::MapSourceDesc::set_uri_format = 8 - - CODE: - switch (ix) { - case 0: - desc->id = g_strdup(SvGChar(sv)); - break; - - case 1: - desc->name = g_strdup(SvGChar(sv)); - break; - - case 2: - desc->license = g_strdup(SvGChar(sv)); - break; - - case 3: - desc->license_uri = g_strdup(SvGChar(sv)); - break; - - case 4: - desc->min_zoom_level = (gint)SvIV(sv); - break; - - case 5: - desc->max_zoom_level = (gint)SvIV(sv); - break; - - case 6: - desc->projection = SvChamplainMapProjection(sv); - break; - - case 7: - /* This is tricky as we have to wrap the Perl sub into a C callback. */ - croak("$desc->set_constructor(\\&code_ref) isn't implemented yet"); - break; - - case 8: - desc->uri_format = g_strdup(SvGChar(sv)); - break; - - default: - croak("Unsupported property %s", GvNAME(CvGV(cv))); - break; - }