]> err.no Git - libchamplain/commitdiff
Champlain::MapSourceFactory has accessors
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Sat, 13 Jun 2009 15:36:51 +0000 (17:36 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 14 Jun 2009 15:11:17 +0000 (11:11 -0400)
The data structure members have now a Perl accessor. This makes the $desc a
more intuive object to use in Perl.

bindings/perl/Champlain/t/ChamplainMapSourceDesc.t
bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs

index 5d19bb21a4ed186e4c1469ea184f8c685fdd5f63..c4e2ad3f89b7532341c2b467fb4684b7e144b1bc 100644 (file)
@@ -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()");
index ef73cf74d5c19846d38833880c5d84fa48a2f8c5..6b09a18822613ba2ae143b6c90ae72312f911ca7 100644 (file)
@@ -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)